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§
Sourcefn spawn<F, T>(&self, label: &str, f: F) -> Handle<T> ⓘ
fn spawn<F, T>(&self, label: &str, f: F) -> Handle<T> ⓘ
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).
Sourcefn stop(&self, value: i32)
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.
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.