pub struct JsPromise<L: NapiValueT, R: NapiValueT>(/* private fields */);
Implementations§
Source§impl<L: NapiValueT + Copy, R: NapiValueT + Copy> JsPromise<L, R>
impl<L: NapiValueT + Copy, R: NapiValueT + Copy> JsPromise<L, R>
pub fn env(&self) -> NapiEnv
pub fn raw(&self) -> napi_value
pub fn value(&self) -> JsValue
Sourcepub fn new(env: NapiEnv) -> NapiResult<JsPromise<L, R>>
pub fn new(env: NapiEnv) -> NapiResult<JsPromise<L, R>>
This API creates a deferred object and a JavaScript promise.
Sourcepub fn resolve(&self, resolution: L) -> NapiResult<()>
pub fn resolve(&self, resolution: L) -> NapiResult<()>
This API resolves a JavaScript promise by way of the deferred object with which it is associated. Thus, it can only be used to resolve JavaScript promises for which the corresponding deferred object is available. This effectively means that the promise must have been created using napi_create_promise() and the deferred object returned from that call must have been retained in order to be passed to this API.
The deferred object is freed upon successful completion.
Sourcepub fn reject(&self, rejection: R) -> NapiResult<()>
pub fn reject(&self, rejection: R) -> NapiResult<()>
This API rejects a JavaScript promise by way of the deferred object with which it is associated. Thus, it can only be used to reject JavaScript promises for which the corresponding deferred object is available. This effectively means that the promise must have been created using napi_create_promise() and the deferred object returned from that call must have been retained in order to be passed to this API.
The deferred object is freed upon successful completion.
Source§impl<L: NapiValueT + Copy + 'static, R: NapiValueT + Copy + 'static> JsPromise<L, R>
impl<L: NapiValueT + Copy + 'static, R: NapiValueT + Copy + 'static> JsPromise<L, R>
Sourcepub fn spawn<T>(
env: NapiEnv,
work: impl FnMut(&mut T) + Send + 'static,
complete: impl FnMut(Self, NapiStatus, T) -> NapiResult<()> + 'static,
) -> NapiResult<JsPromise<L, R>>where
T: Default,
pub fn spawn<T>(
env: NapiEnv,
work: impl FnMut(&mut T) + Send + 'static,
complete: impl FnMut(Self, NapiStatus, T) -> NapiResult<()> + 'static,
) -> NapiResult<JsPromise<L, R>>where
T: Default,
Spawn a busy task in the libuv pool.