Skip to main content

Task

Trait Task 

Source
pub trait Task<Ctx>: 'static {
    // Required method
    fn handle(&mut self, ctx: Ctx) -> impl Future<Output = ()>;
}
Expand description

Business-logic trait. Implemented by users for each task type.

The handler runs inside a single-threaded runtime. Never block it. Offload blocking or long-running IO via tokio::task::spawn, spawn_blocking, or similar.

Required Methods§

Source

fn handle(&mut self, ctx: Ctx) -> impl Future<Output = ()>

Process one context delivered through one of the task’s channels.

This is invoked sequentially by the scheduler loop on the reactor thread; while it is awaiting, no other context for this task is processed. Keep the synchronous portion short, and detach long-running async work via tokio::task::spawn rather than awaiting it inline.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§