简体   繁体   English

从 NAPI 异步工作线程调用回调是否安全?

[英]Is it safe to invoke callbacks from NAPI async worker thread?

In my nodejs NAPI C++ addon, I need to maintain a long-running process in a background thread.在我的 nodejs NAPI C++ 插件中,我需要在后台线程中维护一个长时间运行的进程。 Periodically, the process needs to let the front-end javascript know the current status.进程需要周期性地让前端 javascript 知道当前状态。

I am implementing a Napi::AsyncWorker based class.我正在实现一个基于Napi::AsyncWorker的类。 The idea is that my process will run within the Execute method and periodically invoke the javascript callback that has been provided to the instance.这个想法是我的进程将在Execute方法中运行,并定期调用已提供给实例的 javascript 回调。

Is it safe to invoke callback methods from the Execute method?Execute方法调用回调方法是否安全? Is there any other way?还有别的办法吗? Regards.问候。

You would go better with AsyncWorkerProgress你会更好地使用 AsyncWorkerProgress

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM