pub unsafe extern "C" fn napi_create_async_work(
env: napi_env,
async_resource: napi_value,
async_resource_name: napi_value,
execute: napi_async_execute_callback,
complete: napi_async_complete_callback,
data: *mut c_void,
result: *mut napi_async_work,
) -> napi_statusnapi only.Expand description
Allocate a work object that is used to execute logic asynchronously.
§Arguments
-
env- Current running virtual machine context. -
async_resource- Not supported, can be ignored by passing nullptr. -
async_resource_name- Identifier for the kind of resource that is being provided for diagnostic information exposed by the HiTrace. -
execute- The native function which should be called to execute the logic asynchronously. The given function is called from a worker pool thread and can execute in parallel with the main event loop thread. -
complete- The native function which will be called when the asynchronous logic is completed or is cancelled. The given function is called from the main event loop thread. -
data- User-provided data context. This will be passed back into the execute and complete functions. -
result- The handle to the newly created async work.
§Returns
- Returns the function execution status.
[
napi_ok] If the function executed successfully.
[napi_invalid_arg] If the param env, async_resource_name, execute, complete and(or) result is
nullptr.
Available since API-level: 10