Executor

Trait Executor 

Source
pub trait Executor {
    // Required methods
    fn block_on(&self, f: Pin<Box<dyn Future<Output = ()>>>);
    fn spawn(
        &self,
        f: Pin<Box<dyn Future<Output = ()> + Send>>,
    ) -> Box<dyn Task>;
    fn spawn_blocking<'life0, 'async_trait>(
        &'life0 self,
        f: Box<dyn FnOnce() + Send + 'static>,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided method
    fn spawn_local(
        &self,
        f: Pin<Box<dyn Future<Output = ()>>>,
    ) -> Result<Box<dyn Task>, LocalExecutorError> { ... }
}
Expand description

A common interface for spawning futures on top of an executor

Required Methods§

Source

fn block_on(&self, f: Pin<Box<dyn Future<Output = ()>>>)

Block on a future until completion

Source

fn spawn(&self, f: Pin<Box<dyn Future<Output = ()> + Send>>) -> Box<dyn Task>

Spawn a future and return a handle to track its completion.

Source

fn spawn_blocking<'life0, 'async_trait>( &'life0 self, f: Box<dyn FnOnce() + Send + 'static>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Convert a blocking task into a future, spawning it on a decicated thread pool

Provided Methods§

Source

fn spawn_local( &self, f: Pin<Box<dyn Future<Output = ()>>>, ) -> Result<Box<dyn Task>, LocalExecutorError>

Spawn a non-Send future on the current thread and return a handle to track its completion.

Implementors§

Source§

impl<E: Deref + Sync> Executor for E
where E::Target: Executor + Sync,