目录

Passing a Task with the Specified Priority to an ArkTS Thread from an Asynchronous Thread Using Node-API

You can use napi_call_threadsafe_function_with_priority to pass a task with a specified priority and enqueuing mode to an ArkTS thread from an asynchronous thread in a thread-safe manner. Then, the task will be processed based on its priority and enqueuing mode.

Function Description

napi_status napi_call_threadsafe_function_with_priority(napi_threadsafe_function func, void *data,
                                                        napi_task_priority priority, bool isTail);
Name Description
func Thread-safe function to call.
data Data to be passed from the asynchronous thread to the main thread.
priority Priority of the task. For details, see napi_task_priority.
isTail Whether to add the task to the end (tail) of the task queue. The value true means to add the task to the end of the task queue; the value false means to add the task to the head of the queue.

When to Use

Pass a task to the ArkTS main thread from an asynchronous thread in a thread-safe manner. Then, the task will be processed based on its priority and enqueuing mode.

Calling an ArkTS API Asynchronously

[h2]Example