Trait corona::prelude::CoroutineFuture [] [src]

pub trait CoroutineFuture: Sized {
    type Item;
    type Error;
    fn coro_wait_cleanup(
        self
    ) -> Result<Result<Self::Item, Self::Error>, Dropped>; fn coro_wait(self) -> Result<Self::Item, Self::Error> { ... } }

An extension crate for the Future trait.

This is auto-implemented for everything that implements the Future trait, attaching more methods to them.

Associated Types

The item produced by the future.

The error produced by the future.

Required Methods

A coroutine aware wait on the result that doesn't panic.

This is just like coro_wait, but instead of panicking when the reactor is unexpectadly dropped, it returns Err(Dropped). This might be used to implement manual coroutine cleanup when needed.

Panics

When called outside of the coroutine.

Provided Methods

A coroutine aware wait on the result.

This blocks the current coroutine until the future resolves and returns the result. This is similar to Future::wait. However, this allows other coroutines to run when this one waits.

Note that the future does not have to be 'static.

Panics

This'll panic if the reactor the coroutine was spawned onto is dropped while the method runs.

It also panics when called outside of the coroutine.

Examples

let mut core = Core::new().unwrap();
let handle = core.handle();
let coro = Coroutine::with_defaults(core.handle(), move || {
    let timeout = Timeout::new(Duration::from_millis(50), &handle).unwrap();
    // This would switch to another coroutine if there was one ready.
    // We unwrap, since the error doesn't happen on timeouts.
    timeout.coro_wait().unwrap();
});
core.run(coro).unwrap();

Implementors