[英]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.