napi_reject_deferred
napi_status napi_reject_deferred(napi_env env,
napi_deferred deferred,
napi_value rejection);
-
[in] env
:调用 API 的环境。¥
[in] env
: The environment that the API is invoked under. -
[in] deferred
:要解析其关联 promise 的延迟对象。¥
[in] deferred
: The deferred object whose associated promise to resolve. -
[in] rejection
:用于拒绝 promise 的值。¥
[in] rejection
: The value with which to reject the promise.
此 API 通过与其关联的延迟对象拒绝 JavaScript promise。因此,它只能用于拒绝相应延迟对象可用的 JavaScript promise。这实际上意味着 promise 必须是使用 napi_create_promise()
创建的,并且必须保留从该调用返回的延迟对象才能传递给此 API。
¥This API rejects a JavaScript promise by way of the deferred object
with which it is associated. Thus, it can only be used to reject JavaScript
promises for which the corresponding deferred object is available. This
effectively means that the promise must have been created using
napi_create_promise()
and the deferred object returned from that call must
have been retained in order to be passed to this API.
延迟对象在成功完成后被释放。
¥The deferred object is freed upon successful completion.