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

时间:2019-04-16 22:36:07

标签: node.js

In my nodejs NAPI C++ addon, I need to maintain a long-running process in a background thread. Periodically, the process needs to let the front-end javascript know the current status.

I am implementing a Napi::AsyncWorker based class. 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.

Is it safe to invoke callback methods from the Execute method? Is there any other way? Regards.

1 个答案:

答案 0 :(得分:-1)

您最好使用AsyncWorkerProgress