napi_cancel_async_work
napi_status napi_cancel_async_work(node_api_basic_env env,
napi_async_work work); [in] env:调用该 API 时所处的环境。[in] work:由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.】