napi_create_threadsafe_function
NAPI_EXTERN napi_status
napi_create_threadsafe_function(napi_env env,
napi_value func,
napi_value async_resource,
napi_value async_resource_name,
size_t max_queue_size,
size_t initial_thread_count,
void* thread_finalize_data,
napi_finalize thread_finalize_cb,
void* context,
napi_threadsafe_function_call_js call_js_cb,
napi_threadsafe_function* result); -
[in] env:调用 API 的环境。¥
[in] env: The environment that the API is invoked under. -
[in] func:从另一个线程调用的可选 JavaScript 函数。如果NULL传递给call_js_cb,则必须提供它。¥
[in] func: An optional JavaScript function to call from another thread. It must be provided ifNULLis passed tocall_js_cb. -
[in] async_resource:与将传递给可能的async_hooksinit钩子 的异步工作关联的可选对象。¥
[in] async_resource: An optional object associated with the async work that will be passed to possibleasync_hooksinithooks. -
[in] async_resource_name:一个 JavaScript 字符串,用于为async_hooksAPI 公开的诊断信息提供的资源类型提供标识符。¥
[in] async_resource_name: A JavaScript string to provide an identifier for the kind of resource that is being provided for diagnostic information exposed by theasync_hooksAPI. -
[in] max_queue_size:队列的最大大小。0为无限制。¥
[in] max_queue_size: Maximum size of the queue.0for no limit. -
[in] initial_thread_count:初始获取数,即初始线程数,包括将使用此函数的主线程。¥
[in] initial_thread_count: The initial number of acquisitions, i.e. the initial number of threads, including the main thread, which will be making use of this function. -
[in] thread_finalize_data:要传递给thread_finalize_cb的可选数据。¥
[in] thread_finalize_data: Optional data to be passed tothread_finalize_cb. -
[in] thread_finalize_cb:napi_threadsafe_function被销毁时调用的可选函数。¥
[in] thread_finalize_cb: Optional function to call when thenapi_threadsafe_functionis being destroyed. -
[in] context:附加到生成的napi_threadsafe_function的可选数据。¥
[in] context: Optional data to attach to the resultingnapi_threadsafe_function. -
[in] call_js_cb:可选回调调用 JavaScript 函数以响应不同线程上的调用。此回调将在主线程上调用。如果没有给出,JavaScript 函数将在没有参数的情况下调用,并将undefined作为其this值。napi_threadsafe_function_call_js提供了更多详细信息。¥
[in] call_js_cb: Optional callback which calls the JavaScript function in response to a call on a different thread. This callback will be called on the main thread. If not given, the JavaScript function will be called with no parameters and withundefinedas itsthisvalue.napi_threadsafe_function_call_jsprovides more details. -
[out] result:异步线程安全的 JavaScript 函数。¥
[out] result: The asynchronous thread-safe JavaScript function.
变更历史:
¥Change History:
-
实验性的(定义了
NAPI_EXPERIMENTAL):¥Experimental (
NAPI_EXPERIMENTALis defined):call_js_cb中引发的未捕获异常将由'uncaughtException'事件处理,而不是被忽略。¥Uncaught exceptions thrown in
call_js_cbare handled with the'uncaughtException'event, instead of being ignored.