Skip to main content

AsyncExecutorExt

Trait AsyncExecutorExt 

Source
pub trait AsyncExecutorExt: AsyncExecutor {
    // Provided method
    fn block_on<F>(&self, future: F) -> F::Output
       where F: Future + Send + 'static,
             F::Output: Send + 'static { ... }
}
Expand description

Typed convenience wrapper around AsyncExecutor::block_on_dyn. Implemented for every T: AsyncExecutor; re-introduces the natural block_on<F: Future>(&self, F) -> F::Output signature on top of the type-erased entry point.

§Example

use tokitai_core::{AsyncExecutor, AsyncExecutorExt};

fn drive<E: AsyncExecutor>(exec: &E) -> String {
    exec.block_on(async { String::from("typed output") })
}

Provided Methods§

Source

fn block_on<F>(&self, future: F) -> F::Output
where F: Future + Send + 'static, F::Output: Send + 'static,

Drive a future to completion and return its output.

The future must be Send + 'static (so it can cross the type-erasure boundary) and its output must be Send + 'static (so it can be downcast on the call site).

§Example
use tokitai_core::{AsyncExecutor, AsyncExecutorExt};

fn run<E: AsyncExecutor>(exec: &E) -> i32 {
    exec.block_on(async { 21 + 21 })
}
§Panics

Panics if the internal output slot mutex is poisoned or if the underlying AsyncExecutor::block_on_dyn returns without driving the future to completion.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§