决定是否保持进程运行
【Deciding whether to keep the process running】
与 libuv 句柄类似,线程安全函数可以被“引用”或“取消引用”。一个“被引用”的线程安全函数会导致它所在线程的事件循环保持活跃,直到该线程安全函数被销毁。相比之下,一个“被取消引用”的线程安全函数不会阻止事件循环退出。为此,存在 napi_ref_threadsafe_function 和 napi_unref_threadsafe_function 这些 API。
【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.】