pub trait Spawner:
Clone
+ Send
+ Sync
+ 'static {
// Required method
fn spawn<F, T>(&self, label: &str, f: F) -> Handle<T> ⓘ
where F: Future<Output = T> + Send + 'static,
T: Send + 'static;
}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).
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.