napi_create_threadsafe_function

Function napi_create_threadsafe_function 

Source
pub unsafe extern "C" fn napi_create_threadsafe_function(
    env: napi_env,
    func: napi_value,
    async_resource: napi_value,
    async_resource_name: napi_value,
    max_queue_size: usize,
    initial_thread_count: usize,
    thread_finalize_data: *mut c_void,
    thread_finalize_cb: napi_finalize,
    context: *mut c_void,
    call_js_cb: napi_threadsafe_function_call_js,
    result: *mut napi_threadsafe_function,
) -> napi_status
Available on crate feature napi only.
Expand description

Creates a thread-safe function.

§Arguments

  • env - Current running virtual machine context.

  • func - ArkTS function to be called.

  • async_resource - An optional Object associated with the async work that will be passed to possible ‘async_hooks’.

  • async_resource_name - An ArkTS string to provide an identifier for the kind of resource that is being provided for diagnostic information exposed by the async_hooks interface.

  • max_queue_size - Maximum size of the event queue in the thread-safe function.

  • initial_thread_count - Initial thread count of the thread-safe function.

  • thread_finalize_data - Data passed to the finalize callback.

  • thread_finalize_cb - Finalize callback function which will be triggered when the thread-safe function is released.

  • context - Optional data is passed to ‘call_js_cb’.

  • call_js_cb - Callback function which will be triggered after ‘napi_call_threadsafe_function()’ is called.

  • result - The created thread-safe function.

§Returns

  • Returns the function execution status. [napi_ok] If the function executed successfully.

[napi_invalid_arg] If env, async_resource_name or result is nullptr; max_queue_size is less than 0;

initial_thread_count is greater than 128 or less than 0; func and call_js_cb are

nullptr at same time.

[napi_generic_failure] If create thread-safe function failed.

Available since API-level: 10