pub trait SpawnHelper {
// Provided methods
fn spawn<F>(&self, future: F) -> SpawnHandle<F::Item, F::Error>
where F: Future,
Self: Spawn<Spawned<F>> { ... }
fn spawn_fn<F, R>(&self, f: F) -> SpawnHandle<R::Item, R::Error>
where F: FnOnce() -> R,
R: IntoFuture,
Self: Spawn<Spawned<Lazy<F, R>>> { ... }
}Expand description
Additional strategies for spawning a future.
These functions have to be on a separate trait vs. on the Spawn trait
in order to make rustc happy.
Provided Methods§
Sourcefn spawn<F>(&self, future: F) -> SpawnHandle<F::Item, F::Error>
fn spawn<F>(&self, future: F) -> SpawnHandle<F::Item, F::Error>
Spawns a future to run on this Spawn, returning a future representing
the produced value.
This function will return immediately, and schedule the future f to
run on self. The details of scheduling and execution are left to the
implementations of Spawn. The returned future serves as a proxy to the
computation that F is running.
To simply run an arbitrary closure and extract the result, you can use
the future::lazy combinator to defer work to executing on &self.
Note that if the future f panics it will be caught by default and the
returned future will propagate the panic. That is, panics will not reach
&self and will be propagated to the returned future’s poll method if
queried.
If the returned future is dropped then f will be canceled, if
possible. That is, if the computation is in the middle of working, it
will be interrupted when possible.
Sourcefn spawn_fn<F, R>(&self, f: F) -> SpawnHandle<R::Item, R::Error>
fn spawn_fn<F, R>(&self, f: F) -> SpawnHandle<R::Item, R::Error>
Spawns a closure on this Spawn
This function is a convenience wrapper around the spawn function above
for running a closure wrapped in future::lazy. It will spawn the
function f provided onto the thread pool, and continue to run the
future returned by f on the thread pool as well.
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.