Complete

Struct Complete 

Source
pub struct Complete<T: Send + 'static, E: Send + 'static> { /* private fields */ }
Expand description

An object that is used to fulfill or reject an associated Future.

use eventual::*;

let (tx, future) = Future::<u32, &'static str>::pair();

future.and_then(|v| {
    assert!(v == 1);
    Ok(v + v)
}).fire();

tx.complete(1);

let (tx, future) = Future::<u32, &'static str>::pair();
tx.fail("failed");

future.or_else(|err| {
    assert!(err == "failed");
    Ok::<u32, &'static str>(123)
}).fire();

Implementations§

Source§

impl<T: Send + 'static, E: Send + 'static> Complete<T, E>

Source

pub fn complete(self, val: T)

Fulfill the associated promise with a value

Source

pub fn fail(self, err: E)

Reject the associated promise with an error. The error will be wrapped in Async::Error::Failed.

Source

pub fn abort(self)

Source

pub fn is_ready(&self) -> bool

Source

pub fn is_err(&self) -> bool

Source

pub fn ready<F: FnOnce(Complete<T, E>) + Send + 'static>(self, f: F)

Source

pub fn await(self) -> AsyncResult<Complete<T, E>, ()>

Trait Implementations§

Source§

impl<T: Send + 'static, E: Send + 'static> Async for Complete<T, E>

Source§

type Value = Complete<T, E>

Source§

type Error = ()

Source§

type Cancel = Receipt<Complete<T, E>>

Source§

fn is_ready(&self) -> bool

Returns true if expect will succeed.
Source§

fn is_err(&self) -> bool

Returns true if the async value is ready and has failed
Source§

fn poll(self) -> Result<AsyncResult<Complete<T, E>, ()>, Complete<T, E>>

Get the underlying value if present
Source§

fn ready<F: FnOnce(Complete<T, E>) + Send + 'static>( self, f: F, ) -> Receipt<Complete<T, E>>

Invokes the given function when the Async instance is ready to be consumed.
Source§

fn expect(self) -> AsyncResult<Self::Value, Self::Error>

Get the underlying value if present, panic otherwise
Source§

fn receive<F>(self, f: F)
where F: FnOnce(AsyncResult<Self::Value, Self::Error>) + Send + 'static,

Invoke the callback with the resolved Async result.
Source§

fn await(self) -> AsyncResult<Self::Value, Self::Error>

Blocks the thread until the async value is complete and returns the result.
Source§

fn fire(self)

Trigger the computation without waiting for the result
Source§

fn and<U: Async<Error = Self::Error>>( self, next: U, ) -> Future<U::Value, Self::Error>

This method returns a future whose completion value depends on the completion value of the original future. Read more
Source§

fn and_then<F, U: Async<Error = Self::Error>>( self, f: F, ) -> Future<U::Value, Self::Error>
where F: FnOnce(Self::Value) -> U + Send + 'static, U::Value: Send + 'static,

This method returns a future whose completion value depends on the completion value of the original future. Read more
Source§

fn or<A>(self, alt: A) -> Future<Self::Value, A::Error>
where A: Async<Value = Self::Value>,

This method returns a future whose completion value depends on the completion value of the original future. Read more
Source§

fn or_else<F, A>(self, f: F) -> Future<Self::Value, A::Error>
where F: FnOnce(Self::Error) -> A + Send + 'static, A: Async<Value = Self::Value>,

This method returns a future whose completion value depends on the completion value of the original future. Read more
Source§

impl<T: Send + 'static, E: Send + 'static> Cancel<Complete<T, E>> for Receipt<Complete<T, E>>

Source§

fn cancel(self) -> Option<Complete<T, E>>

Source§

impl<T: Send + 'static, E: Send + 'static> Debug for Complete<T, E>

Source§

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

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

impl<T: Send + 'static, E: Send + 'static> Drop for Complete<T, E>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T, E> Freeze for Complete<T, E>

§

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

§

impl<T, E> Send for Complete<T, E>

§

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

§

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

§

impl<T, E> !UnwindSafe for Complete<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<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.