napi_create_threadsafe_function
functionv4node_api.hNAPI_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: The environment that the API is invoked under.[in] func: An optional JavaScript function to call from another thread. It must be provided ifNULLis passed tocall_js_cb.[in] async_resource: An optional object associated with the async work that will be passed to possibleasync_hooksinithooks.[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: Maximum size of the queue.0for no limit.[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: Optional data to be passed tothread_finalize_cb.[in] thread_finalize_cb: Optional function to call when thenapi_threadsafe_functionis being destroyed.[in] context: Optional data to attach to the resultingnapi_threadsafe_function.[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: The asynchronous thread-safe JavaScript function.
Change History:
-
Version 10 (
NAPI_VERSIONis defined as10or higher):Uncaught exceptions thrown in
call_js_cbare handled with the'uncaughtException'event, instead of being ignored.