pub fn spawn<T>(future: T) -> TaskHandle<T::Output> ⓘ
Expand description
Spawn a task on the tokio multi-threaded executor using “strict” semantics.
This function guarantees that the TaskHandle
will not complete until the
underlying task has completed - even in the case of an error. It achieves this
by blocking inside the TaskHandle
’s destructor until the future has been dropped.
This matches all of the required criteria for structured concurrency, and in doubt crate authors should prefer to use this function.
§Examples
use structured_spawn::spawn;
let value = 12usize;
let handle = spawn(async move {
value * value
});
assert_eq!(handle.await?, 144);