Struct JsPromise

Source
pub struct JsPromise<L: NapiValueT, R: NapiValueT>(/* private fields */);

Implementations§

Source§

impl<L: NapiValueT + Copy, R: NapiValueT + Copy> JsPromise<L, R>

Source

pub fn env(&self) -> NapiEnv

Source

pub fn raw(&self) -> napi_value

Source

pub fn value(&self) -> JsValue

Source

pub fn new(env: NapiEnv) -> NapiResult<JsPromise<L, R>>

This API creates a deferred object and a JavaScript promise.

Source

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.

Source

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>

Source

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.

Trait Implementations§

Source§

impl<L: Clone + NapiValueT, R: Clone + NapiValueT> Clone for JsPromise<L, R>

Source§

fn clone(&self) -> JsPromise<L, R>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<L: Debug + NapiValueT, R: Debug + NapiValueT> Debug for JsPromise<L, R>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<L: NapiValueT + Copy, R: NapiValueT + Copy> NapiValueCheck for JsPromise<L, R>

Source§

impl<L: Copy + NapiValueT, R: Copy + NapiValueT> Copy for JsPromise<L, R>

Auto Trait Implementations§

§

impl<L, R> Freeze for JsPromise<L, R>

§

impl<L, R> RefUnwindSafe for JsPromise<L, R>

§

impl<L, R> !Send for JsPromise<L, R>

§

impl<L, R> !Sync for JsPromise<L, R>

§

impl<L, R> Unpin for JsPromise<L, R>
where L: Unpin, R: Unpin,

§

impl<L, R> UnwindSafe for JsPromise<L, R>
where L: UnwindSafe, R: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.