futures_core::executor

Trait Executor

Source
pub trait Executor {
    // Required method
    fn spawn(
        &mut self,
        f: Box<dyn Future<Item = (), Error = Never> + Send>,
    ) -> Result<(), SpawnError>;

    // Provided method
    fn status(&self) -> Result<(), SpawnError> { ... }
}
Expand description

A task executor.

A task is a ()-producing future that runs at the top level, and will be polled until completion. It’s also the unit at which wake-up notifications occur. Executors, such as thread pools, allow tasks to be spawned and are responsible for putting tasks onto ready queues when they are woken up, and polling them when they are ready.

Required Methods§

Source

fn spawn( &mut self, f: Box<dyn Future<Item = (), Error = Never> + Send>, ) -> Result<(), SpawnError>

Spawn the given task, polling it until completion.

Tasks must be infallible, as the type suggests; it is the client’s reponsibility to route any errors elsewhere via a channel or some other means of communication.

§Errors

The executor may be unable to spawn tasks, either because it has been shut down or is resource-constrained.

Provided Methods§

Source

fn status(&self) -> Result<(), SpawnError>

Determine whether the executor is able to spawn new tasks.

§Returns

An Ok return means the executor is likely (but not guaranteed) to accept a subsequent spawn attempt. Likewise, an Err return means that spawn is likely, but not guaranteed, to yield an error.

Implementors§