Skip to main content

Executor

Trait Executor 

Source
pub trait Executor: Send + Sync {
    // Required methods
    fn spawn(&self, fut: BoxFuture<'static, ()>) -> AbortHandleRef;
    fn spawn_cpu(
        &self,
        task: Box<dyn FnOnce() + Send + 'static>,
    ) -> AbortHandleRef;
    fn spawn_blocking_io(
        &self,
        task: Box<dyn FnOnce() + Send + 'static>,
    ) -> AbortHandleRef;

    // Provided method
    fn spawn_io(&self, fut: BoxFuture<'static, ()>) -> AbortHandleRef { ... }
}
Expand description

Trait used to abstract over different async runtimes.

Required Methods§

Source

fn spawn(&self, fut: BoxFuture<'static, ()>) -> AbortHandleRef

Spawns a future to be executed on the runtime.

The future should continue to be polled in the background by the runtime. The returned AbortHandle may be used to optimistically cancel the future.

Source

fn spawn_cpu(&self, task: Box<dyn FnOnce() + Send + 'static>) -> AbortHandleRef

Spawns a CPU-bound task for execution on the runtime.

The returned AbortHandle may be used to optimistically cancel the task if it has not yet started executing.

Source

fn spawn_blocking_io( &self, task: Box<dyn FnOnce() + Send + 'static>, ) -> AbortHandleRef

Spawns a blocking I/O task for execution on the runtime.

The returned AbortHandle may be used to optimistically cancel the task if it has not yet started executing.

Provided Methods§

Source

fn spawn_io(&self, fut: BoxFuture<'static, ()>) -> AbortHandleRef

Spawns a future doing IO to be executed on the runtime. This allows Executor implementation to split work between multiple async runtime. By default, it just calls Executor::spawn.

Implementations on Foreign Types§

Source§

impl Executor for Executor<'static>

Source§

fn spawn(&self, fut: BoxFuture<'static, ()>) -> AbortHandleRef

Source§

fn spawn_cpu(&self, task: Box<dyn FnOnce() + Send + 'static>) -> AbortHandleRef

Source§

fn spawn_blocking_io( &self, task: Box<dyn FnOnce() + Send + 'static>, ) -> AbortHandleRef

Source§

impl Executor for Handle

Source§

fn spawn(&self, fut: BoxFuture<'static, ()>) -> AbortHandleRef

Source§

fn spawn_cpu(&self, cpu: Box<dyn FnOnce() + Send + 'static>) -> AbortHandleRef

Source§

fn spawn_blocking_io( &self, task: Box<dyn FnOnce() + Send + 'static>, ) -> AbortHandleRef

Implementors§