[][src]Struct callback_future::CallbackFuture

pub struct CallbackFuture<T> { /* fields omitted */ }

An adapter between callbacks and futures.

Allows wrapping asynchronous API with callbacks into futures. Calls loader upon first Future::poll call; stores result and wakes upon getting callback.

Implementations

impl<T> CallbackFuture<T>[src]

pub fn new(
    loader: impl FnOnce(Box<dyn FnOnce(T) + Send + 'static>) + Send + 'static
) -> CallbackFuture<T>
[src]

Creates a new CallbackFuture

Examples

use callback_future::CallbackFuture;
use futures::executor::block_on;
use std::thread;
use std::time::Duration;

let future = CallbackFuture::new(|complete| {
    // make call with callback here, call `complete` upon callback reception, e.g.:
    thread::spawn(move || {
        complete("Test");
    });
});
assert_eq!(block_on(future), "Test");

pub fn ready(value: T) -> CallbackFuture<T>[src]

Creates a ready CallbackFuture

Examples

use callback_future::CallbackFuture;
use futures::executor::block_on;

assert_eq!(block_on(CallbackFuture::ready("Test")), "Test");

Trait Implementations

impl<T: Send + 'static> Future for CallbackFuture<T>[src]

type Output = T

The type of value produced on completion.

Auto Trait Implementations

impl<T> !RefUnwindSafe for CallbackFuture<T>

impl<T> Send for CallbackFuture<T> where
    T: Send

impl<T> !Sync for CallbackFuture<T>

impl<T> Unpin for CallbackFuture<T>

impl<T> !UnwindSafe for CallbackFuture<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> FutureExt for T where
    T: Future + ?Sized
[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<F> IntoFuture for F where
    F: Future
[src]

type Output = <F as Future>::Output

🔬 This is a nightly-only experimental API. (into_future)

The output that the future will produce on completion.

type Future = F

🔬 This is a nightly-only experimental API. (into_future)

Which kind of future are we turning this into?

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<F, T, E> TryFuture for F where
    F: Future<Output = Result<T, E>> + ?Sized
[src]

type Ok = T

The type of successful values yielded by this future

type Error = E

The type of failures yielded by this future

impl<Fut> TryFutureExt for Fut where
    Fut: TryFuture + ?Sized
[src]

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.