Skip to main content

TaskProvider

Trait TaskProvider 

Source
pub trait TaskProvider:
    Clone
    + Send
    + Sync
    + 'static {
    type JoinHandle: Future<Output = Result<(), JoinError>> + Send + Sync + 'static;

    // Required methods
    fn spawn_task<F>(&self, name: &str, future: F) -> Self::JoinHandle
       where F: Future<Output = ()> + Send + 'static;
    fn yield_now(&self) -> impl Future<Output = ()> + Send;
}
Expand description

Provider for spawning tasks.

This trait abstracts task spawning to enable both real tokio tasks and simulation-controlled task scheduling. The simulation runtime runs on a single OS thread, but the spawned futures are Send-bounded so customer call graphs can use Arc<RwLock<…>>, DashMap, and other Send + Sync primitives without contortion.

Required Associated Types§

Source

type JoinHandle: Future<Output = Result<(), JoinError>> + Send + Sync + 'static

Future returned by Self::spawn_task.

Resolves with Ok(()) on normal completion, or a JoinError if the task was cancelled or panicked.

Required Methods§

Source

fn spawn_task<F>(&self, name: &str, future: F) -> Self::JoinHandle
where F: Future<Output = ()> + Send + 'static,

Spawn a named task.

Source

fn yield_now(&self) -> impl Future<Output = ()> + Send

Yield control to allow other tasks to run.

This is equivalent to tokio::task::yield_now() but abstracted to enable simulation control and deterministic behavior.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§