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>
impl<T: Clone + 'static> JsPromise<T>
Sourcepub fn new_pending() -> (Self, ResolveFn<T>, RejectFn)
pub fn new_pending() -> (Self, ResolveFn<T>, RejectFn)
Creates a new pending promise along with resolve and reject controller callbacks.
Sourcepub fn new<F>(executor: F) -> Self
pub fn new<F>(executor: F) -> Self
Constructs a promise by executing an executor closure receiving resolve and reject callbacks.
Sourcepub fn state(&self) -> PromiseState<T>
pub fn state(&self) -> PromiseState<T>
Returns the current state of the promise.
Sourcepub fn then<U: Clone + 'static, F: FnOnce(T) -> U + 'static>(
self,
on_fulfilled: F,
) -> JsPromise<U> ⓘ
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.
Sourcepub fn then_async<U: Clone + 'static, F: FnOnce(T) -> JsPromise<U> + 'static>(
self,
on_fulfilled: F,
) -> JsPromise<U> ⓘ
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>.
Sourcepub fn catch<F: FnOnce(JsValue) -> T + 'static>(
self,
on_rejected: F,
) -> JsPromise<T> ⓘ
pub fn catch<F: FnOnce(JsValue) -> T + 'static>( self, on_rejected: F, ) -> JsPromise<T> ⓘ
Attaches a rejection handler to the promise.
Sourcepub fn finally<F: FnOnce() + 'static>(self, on_finally: F) -> JsPromise<T> ⓘ
pub fn finally<F: FnOnce() + 'static>(self, on_finally: F) -> JsPromise<T> ⓘ
Attaches a callback executed whenever the promise settles (fulfilled or rejected).
Trait Implementations§
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>
impl<T> Move for JsPromise<T>
impl<T> Unpin for JsPromise<T>
impl<T> UnsafeUnpin for JsPromise<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<F> IntoFuture for Fwhere
F: Future,
impl<F> IntoFuture for Fwhere
F: Future,
Source§type IntoFuture = F
type IntoFuture = F
Which kind of future are we turning this into?
Source§fn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
Creates a future from a value. Read more