Skip to main content

TaskExecutor

Trait TaskExecutor 

Source
pub trait TaskExecutor:
    Send
    + Sync
    + 'static {
    type Guard<'a>
       where Self: 'a;

    // Required methods
    fn block_on<T>(&self, task: T) -> T::Output
       where T: Future + Send + 'static,
             T::Output: Send + 'static;
    fn spawn<F>(&self, task: F)
       where F: Future<Output = ()> + Send + 'static;
    fn spawn_blocking<T, R>(&self, task: T) -> BoxFuture<'_, DeltaResult<R>>
       where T: FnOnce() -> R + Send + 'static,
             R: Send + 'static;
    fn enter(&self) -> Self::Guard<'_>;
}
Expand description

An executor that can be used to run async tasks. This is used by IO functions within the DefaultEngine.

This must be capable of running within an async context and running futures on another thread. This could be a multi-threaded runtime, like Tokio’s or could be a single-threaded runtime on a background thread.

Required Associated Types§

Source

type Guard<'a> where Self: 'a

The type of guard returned for enter

Required Methods§

Source

fn block_on<T>(&self, task: T) -> T::Output
where T: Future + Send + 'static, T::Output: Send + 'static,

Block on the given future, returning its output.

This should NOT panic if called within an async context. Thus it can’t be implemented by tokio::runtime::Runtime::block_on.

Source

fn spawn<F>(&self, task: F)
where F: Future<Output = ()> + Send + 'static,

Run the future in the background.

Source

fn spawn_blocking<T, R>(&self, task: T) -> BoxFuture<'_, DeltaResult<R>>
where T: FnOnce() -> R + Send + 'static, R: Send + 'static,

Source

fn enter(&self) -> Self::Guard<'_>

Enter the runtime context of this executor.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§