LocalExecutor

Trait LocalExecutor 

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

A trait for executor implementations that can spawn futures on the current thread.

This trait represents executors that operate within a single thread context, allowing them to work with futures that are not Send. This is essential for working with non-thread-safe types like Rc, RefCell, or thread-local storage.

Required Methods§

Source

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

Spawns a future on this local 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 LocalExecutor for LocalExecutor<'static>

Source§

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

Implementors§