Executor

Trait Executor 

Source
pub trait Executor:
    Clone
    + Send
    + Sync
    + 'static {
    // Required methods
    fn spawn(
        &self,
        f: Pin<Box<dyn Future<Output = ()> + Send>>,
    ) -> Result<(), ()>;
    fn spawn_blocking<F, Res>(&self, f: F) -> JoinHandle<Res> 
       where F: FnOnce() -> Res + Send + 'static,
             Res: Send + 'static;
    fn interval(&self, duration: Duration) -> Interval;
    fn delay(&self, duration: Duration) -> Delay ;
    fn kind(&self) -> ExecutorKind;
}
Expand description

Wrapper trait abstracting the Tokio and async-std executors

Required Methods§

Source

fn spawn(&self, f: Pin<Box<dyn Future<Output = ()> + Send>>) -> Result<(), ()>

spawns a new task

Source

fn spawn_blocking<F, Res>(&self, f: F) -> JoinHandle<Res>
where F: FnOnce() -> Res + Send + 'static, Res: Send + 'static,

spawns a new blocking task

Source

fn interval(&self, duration: Duration) -> Interval

returns a Stream that will produce at regular intervals

Source

fn delay(&self, duration: Duration) -> Delay

waits for a configurable time

Source

fn kind(&self) -> ExecutorKind

returns which executor is currently used

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<Exe: Executor> Executor for Arc<Exe>

Source§

fn spawn(&self, f: Pin<Box<dyn Future<Output = ()> + Send>>) -> Result<(), ()>

Source§

fn spawn_blocking<F, Res>(&self, f: F) -> JoinHandle<Res>
where F: FnOnce() -> Res + Send + 'static, Res: Send + 'static,

Source§

fn interval(&self, duration: Duration) -> Interval

Source§

fn delay(&self, duration: Duration) -> Delay

Source§

fn kind(&self) -> ExecutorKind

Implementors§