Skip to main content

Executor

Trait Executor 

Source
pub trait Executor: Send + Sync {
    type Execution<R: Send + 'static, E: Display + Send + 'static>;

    // Required method
    fn call<C, R, E>(&self, task: C) -> Self::Execution<R, E>
       where C: Callable<R, E> + Send + 'static,
             R: Send + 'static,
             E: Display + Send + 'static;

    // Provided method
    fn execute<T, E>(&self, task: T) -> Self::Execution<(), E>
       where T: Runnable<E> + Send + 'static,
             E: Display + Send + 'static { ... }
}
Expand description

Executes fallible one-time tasks according to an implementation-defined strategy.

Executor models an execution strategy, not a managed task service. An executor may run a task immediately, retry it, delay it, schedule it on another runtime, or return a handle that represents work running elsewhere. The associated Self::Execution type describes how this executor exposes the result of a single execution.

Required Associated Types§

Source

type Execution<R: Send + 'static, E: Display + Send + 'static>

The result carrier returned for one execution.

Implementations choose the carrier that matches their execution model. For example, a direct executor can use Result<R, E>, while a threaded executor can use a task handle and a future-backed executor can use a future.

Required Methods§

Source

fn call<C, R, E>(&self, task: C) -> Self::Execution<R, E>
where C: Callable<R, E> + Send + 'static, R: Send + 'static, E: Display + Send + 'static,

Executes a callable task and returns this executor’s result carrier.

§Parameters
  • task - The fallible computation to execute.
§Returns

The execution carrier for the submitted callable. Its exact behavior is defined by the concrete executor.

Provided Methods§

Source

fn execute<T, E>(&self, task: T) -> Self::Execution<(), E>
where T: Runnable<E> + Send + 'static, E: Display + Send + 'static,

Executes a runnable task and returns this executor’s result carrier.

This is the unit-returning counterpart of Self::call. The returned carrier reports the runnable’s Result<(), E> according to the concrete executor’s execution model.

§Parameters
  • task - The fallible action to execute.
§Returns

The execution carrier for the submitted runnable.

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 DelayExecutor

Source§

type Execution<R: Send + 'static, E: Display + Send + 'static> = TaskHandle<R, E>

Source§

impl Executor for DirectExecutor

Source§

type Execution<R: Send + 'static, E: Display + Send + 'static> = Result<R, E>

Source§

impl Executor for ThreadPerTaskExecutor

Source§

type Execution<R: Send + 'static, E: Display + Send + 'static> = TaskHandle<R, E>

Source§

impl Executor for TokioExecutor

Source§

type Execution<R, E> = TokioExecution<R, E> where R: Send + 'static, E: Display + Send + 'static