Skip to main content

Promise

Enum Promise 

Source
pub enum Promise<T, E>
where T: Unpin, E: PromiseRejection,
{ Pending(BoxedPromiseFuture<T, E>), Resolved(T), Rejected(E), Consumed, }

Variants§

§

Pending(BoxedPromiseFuture<T, E>)

§

Resolved(T)

§

Rejected(E)

§

Consumed

Implementations§

Source§

impl<T, E> Promise<T, E>
where T: Send + Unpin + 'static, E: PromiseRejection,

Source

pub fn all<I>(promises: I) -> Promise<Vec<T>, E>
where I: IntoIterator<Item = Self>,

Source§

impl<T, E> Promise<T, E>
where T: Send + Unpin + 'static, E: PromiseRejection,

Source

pub fn any<I>(promises: I) -> Promise<T, Vec<E>>
where I: IntoIterator<Item = Self>,

Source§

impl<T, E> Promise<T, E>
where T: Send + Unpin + 'static, E: PromiseRejection,

Source

pub fn catch<TO, EO, F, Fut>(self, recover: F) -> Promise<TO, EO>
where TO: From<T> + Unpin + 'static, EO: PromiseRejection + 'static, F: FnOnce(E) -> Fut + Send + 'static, Fut: Future<Output = Result<TO, EO>> + Send + 'static,

Source§

impl<T, E> Promise<T, E>
where T: Unpin, E: PromiseRejection,

Source

pub fn consume(&mut self) -> Option<Result<T, E>>

If settled, consumes and returns the result. Returns None if still pending.

Source§

impl<T, E> Promise<T, E>
where T: Unpin, E: PromiseRejection,

Source

pub const fn is_consumed(&self) -> bool

Source§

impl<T, E> Promise<T, E>
where T: Unpin, E: PromiseRejection,

Source

pub const fn is_pending(&self) -> bool

Source§

impl<T, E> Promise<T, E>
where T: Unpin, E: PromiseRejection,

Source

pub const fn is_ready(&self) -> bool

Source§

impl<T, E> Promise<T, E>
where T: Unpin, E: PromiseRejection,

Source

pub const fn is_rejected(&self) -> bool

Source§

impl<T, E> Promise<T, E>
where T: Unpin, E: PromiseRejection,

Source

pub const fn is_resolved(&self) -> bool

Source§

impl<T, E> Promise<T, E>
where T: Send + Unpin + 'static, E: PromiseRejection,

Source

pub fn map<TO, F, Fut>(self, f: F) -> Promise<TO, E>
where TO: Unpin + 'static, F: FnOnce(T) -> Fut + Send + 'static, Fut: Future<Output = TO> + Send + 'static,

Source§

impl<T, E> Promise<T, E>
where T: Send + Unpin + 'static, E: PromiseRejection,

Source

pub fn map_err<EO, F, Fut>(self, f: F) -> Promise<T, EO>
where EO: PromiseRejection + 'static, F: FnOnce(E) -> Fut + Send + 'static, Fut: Future<Output = EO> + Send + 'static,

Source§

impl<T, E> Promise<T, E>
where T: Unpin, E: PromiseRejection,

Source

pub fn new<F>(future: F) -> Self
where F: Future<Output = Result<T, E>> + Send + 'static,

Source§

impl<T, E> Promise<T, E>
where T: Unpin, E: PromiseRejection,

Source

pub fn pending(&mut self, cx: &mut Context<'_>) -> bool

Polls the promise’s inner future if pending. Returns true if the promise is still pending.

Source§

impl<T, E> Promise<T, E>
where T: Unpin, E: PromiseRejection,

Source

pub fn pending_sync(&mut self) -> bool

Polls the promise’s inner future using a no-op waker. Returns true if the promise is still pending.

Source§

impl<T, E> Promise<T, E>
where T: Unpin, E: PromiseRejection,

Source

pub fn poll(&mut self, cx: &mut Context<'_>)

Attempts to advance this Promise using the provided execution Context.

This performs exactly one poll of the underlying future.

Source§

impl<T, E> Promise<T, E>
where T: Unpin, E: PromiseRejection,

Source

pub fn poll_sync(&mut self)

Attempts to advance this Promise immediately on the current thread.

This performs exactly one poll of the underlying future using a no-op waker.

Wakes triggered during this synchronous poll are ignored. Execution will effectively resume only when the Promise is polled again by a real executor.

Source§

impl<T, E> Promise<T, E>
where T: Send + Unpin + 'static, E: PromiseRejection,

Source

pub fn race<I>(promises: I) -> Self
where I: IntoIterator<Item = Self>,

Source§

impl<T, E> Promise<T, E>
where T: Unpin, E: PromiseRejection,

Source

pub fn ready(&mut self, cx: &mut Context<'_>) -> bool

Polls the promise’s inner future if pending. Returns true if the promise is now resolved or rejected.

Source§

impl<T, E> Promise<T, E>
where T: Unpin, E: PromiseRejection,

Source

pub fn ready_sync(&mut self) -> bool

Polls the promise’s inner future using a no-op waker. Returns true if the promise is now resolved or rejected.

Source§

impl<T, E> Promise<T, E>
where T: Unpin, E: PromiseRejection,

Source

pub const fn reject(err: E) -> Self

Source§

impl<T, E> Promise<T, E>
where T: Unpin, E: PromiseRejection,

Source

pub const fn resolve(value: T) -> Self

Source§

impl<T, E> Promise<T, E>
where T: Send + Unpin + 'static, E: PromiseRejection,

Source

pub fn then<TO, EO, F, Fut>(self, f: F) -> Promise<TO, EO>
where TO: Unpin + 'static, EO: PromiseRejection + From<E> + 'static, F: FnOnce(T) -> Fut + Send + 'static, Fut: Future<Output = Result<TO, EO>> + Send + 'static,

Source§

impl<T, E> Promise<T, WrappedPromiseRejection<E>>
where T: Unpin, E: Send + Unpin + 'static,

Source

pub fn wrap(future: impl Future<Output = Result<T, E>> + Send + 'static) -> Self

Trait Implementations§

Source§

impl<T, E> Debug for Promise<T, E>
where T: Unpin + Debug, E: PromiseRejection + Debug,

Source§

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

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

impl<T, E> Default for Promise<T, E>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T, E> Future for Promise<T, E>
where T: Unpin, E: PromiseRejection,

Source§

type Output = Result<T, E>

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

Auto Trait Implementations§

§

impl<T, E> Freeze for Promise<T, E>
where T: Freeze, E: Freeze,

§

impl<T, E> !RefUnwindSafe for Promise<T, E>

§

impl<T, E> Send for Promise<T, E>
where T: Send,

§

impl<T, E> !Sync for Promise<T, E>

§

impl<T, E> Unpin for Promise<T, E>

§

impl<T, E> UnsafeUnpin for Promise<T, E>
where T: UnsafeUnpin, E: UnsafeUnpin,

§

impl<T, E> !UnwindSafe for Promise<T, E>

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> 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, 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.