Trait Executor

Source
pub trait Executor: Send + Sync {
    // Required methods
    fn block_on(
        &self,
        future: Pin<Box<dyn Future<Output = ()> + Send + 'static>>,
    );
    fn spawn(
        &self,
        future: Pin<Box<dyn Future<Output = ()> + Send + 'static>>,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>>;
    fn spawn_blocking(
        &self,
        task: Box<dyn FnOnce() + Send>,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>>;
    fn spawn_local(
        &self,
        future: Pin<Box<dyn Future<Output = ()> + 'static>>,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>>;
}
Expand description

Trait abstracting over an executor.

Required Methods§

Source

fn block_on(&self, future: Pin<Box<dyn Future<Output = ()> + Send + 'static>>)

Blocks until the future has finished.

Source

fn spawn( &self, future: Pin<Box<dyn Future<Output = ()> + Send + 'static>>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>>

Spawns an asynchronous task using the underlying executor.

Source

fn spawn_blocking( &self, task: Box<dyn FnOnce() + Send>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>>

Runs the provided closure on a thread, which can execute blocking tasks asynchronously.

Source

fn spawn_local( &self, future: Pin<Box<dyn Future<Output = ()> + 'static>>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>>

Spawns a future that doesn’t implement Send.

The spawned future will be executed on the same thread that called spawn_local.

Implementors§