pub struct Deferred { /* private fields */ }
This is supported on crate feature
promise-api
only.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
sourceimpl Deferred
impl Deferred
sourcepub fn resolve<'a, V, C>(self, cx: &mut C, value: Handle<'_, V>) where
V: Value,
C: Context<'a>,
pub fn resolve<'a, V, C>(self, cx: &mut C, value: Handle<'_, V>) where
V: Value,
C: Context<'a>,
Resolve a JsPromise
with a JavaScript value
sourcepub fn reject<'a, V, C>(self, cx: &mut C, value: Handle<'_, V>) where
V: Value,
C: Context<'a>,
pub fn reject<'a, V, C>(self, cx: &mut C, value: Handle<'_, V>) where
V: Value,
C: Context<'a>,
Reject a JsPromise
with a JavaScript value
sourcepub fn try_settle_with<V, F>(
self,
channel: &Channel,
complete: F
) -> Result<JoinHandle<()>, SendError> where
V: Value,
F: FnOnce(TaskContext<'_>) -> JsResult<'_, V> + Send + 'static,
This is supported on crate feature channel-api
only.
pub fn try_settle_with<V, F>(
self,
channel: &Channel,
complete: F
) -> Result<JoinHandle<()>, SendError> where
V: Value,
F: FnOnce(TaskContext<'_>) -> JsResult<'_, V> + Send + 'static,
This is supported on crate feature
channel-api
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<()> where
V: Value,
F: FnOnce(TaskContext<'_>) -> JsResult<'_, V> + Send + 'static,
This is supported on crate feature channel-api
only.
pub fn settle_with<V, F>(self, channel: &Channel, complete: F) -> JoinHandle<()> where
V: Value,
F: FnOnce(TaskContext<'_>) -> JsResult<'_, V> + Send + 'static,
This is supported on crate feature
channel-api
only.Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Deferred
impl Send for Deferred
impl !Sync for Deferred
impl Unpin for Deferred
impl UnwindSafe for Deferred
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