#[repr(transparent)]
pub struct JsPromise(_);
Expand description

The JavaScript Promise value.

JsPromise may be constructed with Context::promise.

Implementations

Creates a new Promise immediately resolved with the given value. If the value is a Promise or a then-able, it will be flattened.

JsPromise::resolve is useful to ensure a value that might not be a Promise or might not be a native promise is converted to a Promise before use.

Creates a nwe Promise immediately rejected with the given error.

Available on crate features napi-5 and futures only.

Creates a Future that can be awaited to receive the result of a JavaScript Promise.

A callback must be provided that maps a Result representing the resolution or rejection of the Promise and returns a value as the Future output.

Note: Unlike Future, Promise are eagerly evaluated and so are JsFuture.

Trait Implementations

Formats the value using the given formatter. Read more
Gets a property from a JavaScript object that may be undefined and attempts to downcast the value if it existed. Read more
Gets a property from a JavaScript object as a JsValue. Read more
Gets a property from a JavaScript object and attempts to downcast as a specific type. Equivalent to calling obj.get_value(&mut cx)?.downcast_or_throw(&mut cx). Read more
Available on crate feature napi-6 only.

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.