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] func
: The asynchronous thread-safe JavaScript function to invoke. -
[in] data
:通过创建线程安全 JavaScript 函数期间提供的回调call_js_cb
发送到 JavaScript 的数据。¥
[in] data
: Data to send into JavaScript via the callbackcall_js_cb
provided during the creation of the thread-safe JavaScript function. -
[in] is_blocking
:标志,其值可以是napi_tsfn_blocking
,表示如果队列已满,调用应该阻塞;也可以是napi_tsfn_nonblocking
,表示只要队列已满,调用就应该立即返回,状态为napi_queue_full
。¥
[in] is_blocking
: Flag whose value can be eithernapi_tsfn_blocking
to indicate that the call should block if the queue is full ornapi_tsfn_nonblocking
to indicate that the call should return immediately with a status ofnapi_queue_full
whenever the queue is 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
.
可以从使用 func
的任何线程调用此 API。
¥This API may be called from any thread which makes use of func
.