commonware_runtime

Trait Spawner

Source
pub trait Spawner:
    Clone
    + Send
    + Sync
    + 'static {
    // Required methods
    fn spawn<F, T>(&self, label: &str, f: F) -> Handle<T> 
       where F: Future<Output = T> + Send + 'static,
             T: Send + 'static;
    fn stop(&self, value: i32);
    fn stopped(&self) -> Signal;
}
Expand description

Interface that any task scheduler must implement to spawn sub-tasks in a given root task.

Required Methods§

Source

fn spawn<F, T>(&self, label: &str, f: F) -> Handle<T>
where F: Future<Output = T> + Send + 'static, T: Send + 'static,

Enqueues a task to be executed.

Label can be used to track how many instances of a specific type of task have been spawned or are running concurrently (and is appened to all metrics). Label is automatially appended to the parent task labels (i.e. spawning “fun” from “have” will be labeled “have_fun”).

Unlike a future, a spawned task will start executing immediately (even if the caller does not await the handle).

Source

fn stop(&self, value: i32)

Signals the runtime to stop execution and that all outstanding tasks should perform any required cleanup and exit. This method is idempotent and can be called multiple times.

This method does not actually kill any tasks but rather signals to them, using the Signal returned by stopped, that they should exit.

Source

fn stopped(&self) -> Signal

Returns an instance of a Signal that resolves when stop is called by any task.

If stop has already been called, the returned Signal will resolve immediately.

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 Spawner for commonware_runtime::deterministic::Context

Source§

impl Spawner for commonware_runtime::tokio::Context