napi_cancel_async_work


napi_status napi_cancel_async_work(node_api_nogc_env env,
                                   napi_async_work work); 
  • [in] env:调用 API 的环境。

    ¥[in] env: The environment that the API is invoked under.

  • [in] work:调用 napi_create_async_work 返回的句柄。

    ¥[in] work: The handle returned by the call to napi_create_async_work.

如果 API 成功,则返回 napi_ok

¥Returns napi_ok if the API succeeded.

如果尚未启动,此 API 会取消排队的工作。如果已经开始执行,则无法取消,返回 napi_generic_failure。如果成功,将调用 complete 回调,状态值为 napi_cancelled。在 complete 回调调用之前不应删除该工作,即使它已成功取消。

¥This API cancels queued work if it has not yet been started. If it has already started executing, it cannot be cancelled and napi_generic_failure will be returned. If successful, the complete callback will be invoked with a status value of napi_cancelled. The work should not be deleted before the complete callback invocation, even if it has been successfully cancelled.

即使存在挂起的 JavaScript 异常,也可以调用此 API。

¥This API can be called even if there is a pending JavaScript exception.