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>)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,
Available on crate feature napi-4
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,
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<()> ⓘwhere
V: Value,
F: FnOnce(TaskContext<'_>) -> JsResult<'_, V> + Send + 'static,
Available on crate feature napi-4
only.
pub fn settle_with<V, F>(self, channel: &Channel, complete: F) -> JoinHandle<()> ⓘwhere V: Value, F: FnOnce(TaskContext<'_>) -> JsResult<'_, V> + Send + 'static,
napi-4
only.