决定是否保持进程运行


¥Deciding whether to keep the process running

与 libuv 句柄类似,线程安全函数可以是 "referenced" 和 "unreferenced"。"referenced" 线程安全函数将导致创建它的线程上的事件循环保持活动状态,直到线程安全函数被销毁。相反,"unreferenced" 线程安全函数不会阻止事件循环退出。API napi_ref_threadsafe_functionnapi_unref_threadsafe_function 就是为此目的而存在的。

¥Similarly to libuv handles, thread-safe functions can be "referenced" and "unreferenced". A "referenced" thread-safe function will cause the event loop on the thread on which it is created to remain alive until the thread-safe function is destroyed. In contrast, an "unreferenced" thread-safe function will not prevent the event loop from exiting. The APIs napi_ref_threadsafe_function and napi_unref_threadsafe_function exist for this purpose.

napi_unref_threadsafe_function 既没有将线程安全函数标记为可以被销毁,也没有 napi_ref_threadsafe_function 阻止它被销毁。

¥Neither does napi_unref_threadsafe_function mark the thread-safe functions as able to be destroyed nor does napi_ref_threadsafe_function prevent it from being destroyed.