Executor

Trait Executor 

Source
pub trait Executor {
    // Required method
    fn spawn<T: Send + 'static>(
        &self,
        fut: impl Future<Output = T> + Send + 'static,
    ) -> Task<T> ;
}
Expand description

A trait for executor implementations that can spawn thread-safe futures.

This trait represents executors capable of running concurrent tasks that are Send, meaning they can be safely moved between threads. Implementors provide the core functionality for task spawning in a multi-threaded context.

Required Methods§

Source

fn spawn<T: Send + 'static>( &self, fut: impl Future<Output = T> + Send + 'static, ) -> Task<T>

Spawns a thread-safe future on this executor.

Returns an async_task::Task handle that can be used to:

  • Await the result
  • Cancel the task
  • Detach the task to run in background

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Executor for &Runtime

Source§

fn spawn<T: Send + 'static>( &self, fut: impl Future<Output = T> + Send + 'static, ) -> Task<T>

Source§

impl Executor for Arc<Runtime>

Source§

fn spawn<T: Send + 'static>( &self, fut: impl Future<Output = T> + Send + 'static, ) -> Task<T>

Source§

impl Executor for Executor<'static>

Source§

fn spawn<T: Send + 'static>( &self, fut: impl Future<Output = T> + Send + 'static, ) -> Task<T>

Source§

impl Executor for Runtime

Source§

fn spawn<T: Send + 'static>( &self, fut: impl Future<Output = T> + Send + 'static, ) -> Task<T>

Implementors§