pub struct Deferred { /* private fields */ }Expand description
A controller struct 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.
§Examples
Implementations§
Source§impl Deferred
impl Deferred
Sourcepub fn resolve<'a, V, C>(self, cx: &mut C, value: Handle<'_, V>)
pub fn resolve<'a, V, C>(self, cx: &mut C, value: Handle<'_, V>)
Resolve a JsPromise with a JavaScript value
Sourcepub fn reject<'a, V, C>(self, cx: &mut C, value: Handle<'_, V>)
pub fn reject<'a, V, C>(self, cx: &mut C, value: Handle<'_, V>)
Reject a JsPromise with a JavaScript value
Sourcepub fn try_settle_with<V, F>(
self,
channel: &Channel,
complete: F,
) -> Result<JoinHandle<()>, SendError>
Available on crate feature napi-4 only.
pub fn try_settle_with<V, F>( self, channel: &Channel, complete: F, ) -> Result<JoinHandle<()>, SendError>
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.
Sourcepub fn settle_with<V, F>(self, channel: &Channel, complete: F) -> JoinHandle<()> ⓘ
Available on crate feature napi-4 only.
pub fn settle_with<V, F>(self, channel: &Channel, complete: F) -> JoinHandle<()> ⓘ
napi-4 only.Sourcepub fn try_settle<V, T>(
self,
channel: &Channel,
v: T,
) -> Result<JoinHandle<()>, SendError>
Available on crate feature napi-4 only.
pub fn try_settle<V, T>( self, channel: &Channel, v: T, ) -> Result<JoinHandle<()>, SendError>
napi-4 only.Settle the JsPromise by sending a type that implements TryIntoJs to the main JavaScript thread.
Usage is identical to Deferred::settle.
Returns a SendError if sending the closure to the main JavaScript thread fails.
See Channel::try_send for more details.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Deferred
impl RefUnwindSafe for Deferred
impl Send for Deferred
impl !Sync for Deferred
impl Unpin for Deferred
impl UnwindSafe for Deferred
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more