napi_call_threadsafe_function
NAPI_EXTERN napi_status
napi_call_threadsafe_function(napi_threadsafe_function func,
void* data,
napi_threadsafe_function_call_mode is_blocking); [in] func:要调用的异步线程安全的 JavaScript 函数。[in] data:通过在创建线程安全的 JavaScript 函数时提供的回调call_js_cb发送到 JavaScript 的数据。[in] is_blocking:标志,其值可以是napi_tsfn_blocking,表示如果队列已满调用应阻塞,或者是napi_tsfn_nonblocking,表示如果队列已满调用应立即返回,状态为napi_queue_full。
不应从 JavaScript 线程使用 napi_tsfn_blocking 调用此 API,因为如果队列已满,可能会导致 JavaScript 线程死锁。
【This API should not be called with napi_tsfn_blocking from a JavaScript
thread, because, if the queue is full, it may cause the JavaScript thread to
deadlock.】
如果从任何线程调用 napi_release_threadsafe_function() 并将 abort 设置为 napi_tsfn_abort,此 API 将返回 napi_closing。仅当 API 返回 napi_ok 时,该值才会被添加到队列中。
【This API will return napi_closing if napi_release_threadsafe_function() was
called with abort set to napi_tsfn_abort from any thread. The value is only
added to the queue if the API returns napi_ok.】
这个 API 可以从任何使用 func 的线程调用。
【This API may be called from any thread which makes use of func.】