pub struct Deferred { /* private fields */ }
Expand description

Deferred is a handle that can be used to resolve or reject a JsPromise

It is recommended to settle a Deferred with Deferred::settle_with to ensure exceptions are caught.

On Node-API versions less than 6, dropping a Deferred without settling will cause a panic. On Node-API 6+, the associated JsPromise will be automatically rejected.

Implementations

Resolve a JsPromise with a JavaScript value

Reject a JsPromise with a JavaScript value

Available on crate feature napi-4 only.

Settle the JsPromise by sending a closure across a Channel to be executed on the main JavaScript thread.

Usage is identical to Deferred::settle_with.

Returns a SendError if sending the closure to the main JavaScript thread fails. See Channel::try_send for more details.

Available on crate feature napi-4 only.

Settle the JsPromise by sending a closure across a Channel to be executed on the main JavaScript thread.

Panics if there is a libuv error.

let channel = cx.channel();
let (deferred, promise) = cx.promise();

deferred.settle_with(&channel, move |mut cx| Ok(cx.number(42)));

Trait Implementations

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.