#[repr(transparent)]pub struct JsPromise(_);
Expand description
The JavaScript Promise
value.
JsPromise
may be constructed with Context::promise
.
Implementations
sourceimpl JsPromise
impl JsPromise
sourcepub fn resolve<'a, C: Context<'a>, T: Value>(
cx: &mut C,
value: Handle<'_, T>
) -> Handle<'a, Self>
pub fn resolve<'a, C: Context<'a>, T: Value>(
cx: &mut C,
value: Handle<'_, T>
) -> Handle<'a, Self>
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.
sourcepub fn reject<'a, C: Context<'a>, E: Value>(
cx: &mut C,
err: Handle<'_, E>
) -> Handle<'a, Self>
pub fn reject<'a, C: Context<'a>, E: Value>(
cx: &mut C,
err: Handle<'_, E>
) -> Handle<'a, Self>
Creates a nwe Promise
immediately rejected with the given error.
sourcepub fn to_future<'a, O, C, F>(&self, cx: &mut C, f: F) -> NeonResult<JsFuture<O>> where
O: Send + 'static,
C: Context<'a>,
F: FnOnce(TaskContext<'_>, Result<Handle<'_, JsValue>, Handle<'_, JsValue>>) -> NeonResult<O> + Send + 'static,
Available on crate features napi-5
and futures
only.
pub fn to_future<'a, O, C, F>(&self, cx: &mut C, f: F) -> NeonResult<JsFuture<O>> where
O: Send + 'static,
C: Context<'a>,
F: FnOnce(TaskContext<'_>, Result<Handle<'_, JsValue>, Handle<'_, JsValue>>) -> NeonResult<O> + Send + 'static,
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
sourceimpl Object for JsPromise
impl Object for JsPromise
sourcefn get_opt<'a, V: Value, C: Context<'a>, K: PropertyKey>(
&self,
cx: &mut C,
key: K
) -> NeonResult<Option<Handle<'a, V>>>
fn get_opt<'a, V: Value, C: Context<'a>, K: PropertyKey>(
&self,
cx: &mut C,
key: K
) -> NeonResult<Option<Handle<'a, V>>>
Gets a property from a JavaScript object that may be undefined
and
attempts to downcast the value if it existed. Read more
sourcefn get_value<'a, C: Context<'a>, K: PropertyKey>(
&self,
cx: &mut C,
key: K
) -> NeonResult<Handle<'a, JsValue>>
fn get_value<'a, C: Context<'a>, K: PropertyKey>(
&self,
cx: &mut C,
key: K
) -> NeonResult<Handle<'a, JsValue>>
sourcefn get<'a, V: Value, C: Context<'a>, K: PropertyKey>(
&self,
cx: &mut C,
key: K
) -> NeonResult<Handle<'a, V>>
fn get<'a, V: Value, C: Context<'a>, K: PropertyKey>(
&self,
cx: &mut C,
key: K
) -> NeonResult<Handle<'a, V>>
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
sourcefn get_own_property_names<'a, C: Context<'a>>(
&self,
cx: &mut C
) -> JsResult<'a, JsArray>
fn get_own_property_names<'a, C: Context<'a>>(
&self,
cx: &mut C
) -> JsResult<'a, JsArray>
napi-6
only.fn freeze<'a, C: Context<'a>>(&self, cx: &mut C) -> NeonResult<&Self>
fn seal<'a, C: Context<'a>>(&self, cx: &mut C) -> NeonResult<&Self>
fn set<'a, C: Context<'a>, K: PropertyKey, W: Value>(
&self,
cx: &mut C,
key: K,
val: Handle<'_, W>
) -> NeonResult<bool>
fn root<'a, C: Context<'a>>(&self, cx: &mut C) -> Root<Self>
fn call_method_with<'a, C, K>(
&self,
cx: &mut C,
method: K
) -> NeonResult<CallOptions<'a>> where
C: Context<'a>,
K: PropertyKey,
Auto Trait Implementations
impl RefUnwindSafe for JsPromise
impl !Send for JsPromise
impl !Sync for JsPromise
impl Unpin for JsPromise
impl UnwindSafe for JsPromise
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more