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§
Sourcefn spawn(&self, fut: BoxFuture<'static, ()>) -> AbortHandleRef
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.
Sourcefn spawn_cpu(&self, task: Box<dyn FnOnce() + Send + 'static>) -> AbortHandleRef
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.
Sourcefn spawn_blocking_io(
&self,
task: Box<dyn FnOnce() + Send + 'static>,
) -> AbortHandleRef
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§
Sourcefn spawn_io(&self, fut: BoxFuture<'static, ()>) -> AbortHandleRef
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.