Skip to main content

JsPromise

Struct JsPromise 

Source
pub struct JsPromise<T> { /* private fields */ }
Expand description

Dynamic, cooperative JavaScript-style Promise with Rust Future implementation.

Implementations§

Source§

impl<T: Clone + 'static> JsPromise<T>

Source

pub fn new_pending() -> (Self, ResolveFn<T>, RejectFn)

Creates a new pending promise along with resolve and reject controller callbacks.

Source

pub fn new<F>(executor: F) -> Self
where F: FnOnce(ResolveFn<T>, RejectFn),

Constructs a promise by executing an executor closure receiving resolve and reject callbacks.

Source

pub fn resolve(val: T) -> Self

Creates an immediately resolved promise.

Source

pub fn reject(err: impl Into<JsValue>) -> Self

Creates an immediately rejected promise.

Source

pub fn state(&self) -> PromiseState<T>

Returns the current state of the promise.

Source

pub fn then<U: Clone + 'static, F: FnOnce(T) -> U + 'static>( self, on_fulfilled: F, ) -> JsPromise<U> ⓘ

Attaches a fulfillment callback transforming value of type T into U.

Source

pub fn then_async<U: Clone + 'static, F: FnOnce(T) -> JsPromise<U> + 'static>( self, on_fulfilled: F, ) -> JsPromise<U> ⓘ

Attaches an async fulfillment callback returning another JsPromise<U>.

Source

pub fn catch<F: FnOnce(JsValue) -> T + 'static>( self, on_rejected: F, ) -> JsPromise<T> ⓘ

Attaches a rejection handler to the promise.

Source

pub fn finally<F: FnOnce() + 'static>(self, on_finally: F) -> JsPromise<T> ⓘ

Attaches a callback executed whenever the promise settles (fulfilled or rejected).

Source

pub fn all(promises: Vec<JsPromise<T>>) -> JsPromise<Vec<T>> ⓘ

Promise.all: Resolves when all promises resolve, or rejects when any rejects.

Source

pub fn race(promises: Vec<JsPromise<T>>) -> JsPromise<T> ⓘ

Promise.race: Settles as soon as the first promise settles.

Trait Implementations§

Source§

impl<T> Clone for JsPromise<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Clone + Debug> Debug for JsPromise<T>

Source§

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

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

impl From<JsPromise<JsValue>> for JsValue

Source§

fn from(p: JsPromise<JsValue>) -> Self

Converts to this type from the input type.
Source§

impl<T: Clone + 'static> Future for JsPromise<T>

Source§

type Output = Result<T, JsValue>

The type of value produced on completion.
Source§

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>

Attempts to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more
Source§

impl<T> PartialEq for JsPromise<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for JsPromise<T>

§

impl<T> !Send for JsPromise<T>

§

impl<T> !Sync for JsPromise<T>

§

impl<T> !UnwindSafe for JsPromise<T>

§

impl<T> Forget for JsPromise<T>

§

impl<T> Freeze for JsPromise<T>
where Rc<RefCell<PromiseInner<T>>>: Freeze,

§

impl<T> Move for JsPromise<T>

§

impl<T> Unpin for JsPromise<T>
where Rc<RefCell<PromiseInner<T>>>: Unpin,

§

impl<T> UnsafeUnpin for JsPromise<T>
where Rc<RefCell<PromiseInner<T>>>: UnsafeUnpin,

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<F> IntoFuture for F
where F: Future,

Source§

type Output = <F as Future>::Output

The output that the future will produce on completion.
Source§

type IntoFuture = F

Which kind of future are we turning this into?
Source§

fn into_future(self) -> <F as IntoFuture>::IntoFuture

Creates a future from a value. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.