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

pub trait CoroutineFuture: Future + Sized {
    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.

Required methods

fn coro_wait_cleanup(self) -> Result<Result<Self::Item, Self::Error>, Dropped>

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 unexpectedly dropped, it returns Err(Dropped). This might be used to implement manual coroutine cleanup when needed.

Panics

When called outside of the coroutine. Also, panics from within the future are propagated to the calling (current) coroutine.

Loading content...

Provided methods

fn coro_wait(self) -> Result<Self::Item, Self::Error>

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 and any panics from the coroutine itself will be propagated to the calling coroutine.

Examples

Coroutine::new().run(move || {
    let timeout = Delay::new(clock::now() + Duration::from_millis(50));
    // 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();
});
Loading content...

Implementors

impl<F: Future> CoroutineFuture for F[src]

Loading content...