napi_release_threadsafe_function


NAPI_EXTERN napi_status
napi_release_threadsafe_function(napi_threadsafe_function func,
                                 napi_threadsafe_function_release_mode mode); 
  • [in] func:要递减引用计数的异步线程安全 JavaScript 函数。
  • [in] mode:标志,其值可以是 napi_tsfn_release,表示当前线程将不再调用线程安全函数;或者是 napi_tsfn_abort,表示除了当前线程外,其他线程也不应再调用线程安全函数。如果设置为 napi_tsfn_abort,后续对 napi_call_threadsafe_function() 的调用将返回 napi_closing,并且队列中不会再放入新的值。

当线程不再使用 func 时,应调用此 API。在调用此 API 后将 func 传递给任何线程安全的 API 会产生未定义的结果,因为 func 可能已经被销毁。

【A thread should call this API when it stops making use of func. Passing func to any thread-safe APIs after having called this API has undefined results, as func may have been destroyed.】

此 API 可以从任何线程调用,该线程将停止使用 func

【This API may be called from any thread which will stop making use of func.】