pub fn spawn_local<T: 'static>(
future: impl Future<Output = T> + 'static,
) -> Task<T> ⓘExpand description
Spawns a task onto the current single-threaded executor.
If called from a tokio LocalSet, the task is spawned on it.
Otherwise, this method panics.
Returns a Task<T> that implements Future<Output = Result<T, TaskError>>.
The task can be awaited to retrieve its result.
§Panics
Panics if called outside of a LocalSet context.
§Example
use sansio_executor::{LocalExecutorBuilder, spawn_local};
LocalExecutorBuilder::default().run(async {
let task1 = spawn_local(async { 1 + 1 });
let task2 = spawn_local(async { 2 + 2 });
let result1 = task1.await.unwrap();
let result2 = task2.await.unwrap();
println!("Results: {}, {}", result1, result2);
});