Executor

Trait Executor 

Source
pub trait Executor:
    Send
    + Sync
    + 'static {
    type AsyncJoin<T: Send + 'static>: AsyncJoin<Item = T>;
    type SyncJoin<T: Send + 'static>: SyncJoin<Item = T>;

    // Required methods
    fn spawn_async<T, F>(future: F) -> Self::AsyncJoin<T>
       where T: Send + Sync + 'static,
             F: Future<Output = T> + Send + 'static;
    fn spawn_sync<T, C>(closure: C) -> Self::SyncJoin<T>
       where T: Send + Sync + 'static,
             C: FnOnce() -> T + Send + 'static;
}
Expand description

Abstract executor for actors

Required Associated Types§

Source

type AsyncJoin<T: Send + 'static>: AsyncJoin<Item = T>

Async join handle

Source

type SyncJoin<T: Send + 'static>: SyncJoin<Item = T>

Sync join handle

Required Methods§

Source

fn spawn_async<T, F>(future: F) -> Self::AsyncJoin<T>
where T: Send + Sync + 'static, F: Future<Output = T> + Send + 'static,

Spawns a future onto the executor as a task, returning a handle that can be .awaited for its result

On async executors, this corresponds to an asynchronous task. On the Threads executor, this corresponds to a new thread with a single-threaded futures executor running on it.

Source

fn spawn_sync<T, C>(closure: C) -> Self::SyncJoin<T>
where T: Send + Sync + 'static, C: FnOnce() -> T + Send + 'static,

Spawns a closure onto its own system thread or blocking task, returning a handle that can be blocked on for its result

On async executors this corresponds to a task on the blocking thread pool, or a new thread if the executor does not provide a blocking thread pool On the Threads executor, this corresponds to a new thread.

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.

Implementors§

Source§

impl Executor for AsyncStd

Source§

type AsyncJoin<T: Send + 'static> = JoinHandle<T>

Source§

type SyncJoin<T: Send + 'static> = JoinHandle<T>

Source§

impl Executor for Threads

Source§

type AsyncJoin<T: Send + 'static> = ThreadJoin<T>

Source§

type SyncJoin<T: Send + 'static> = ThreadJoin<T>