pub fn spawn_local<T>(
future: impl Future<Output = T> + 'static,
) -> JoinHandle<T> ⓘExpand description
Spawns a new future on the current thread.
This function may be used to spawn tasks when the message loop is not
running. The provided future will start running once the message loop
is entered with block_on or MessageLoop::run.
Examples found in repository?
examples/basic.rs (lines 22-27)
19fn main() {
20 println!("hello");
21 block_on(async {
22 let task = spawn_local(async {
23 println!("async hello 1");
24 poll_n_times(3).await;
25 println!("async bye 1");
26 "async 1 result"
27 });
28
29 println!("async hello 2");
30 poll_n_times(2).await;
31 println!("async bye 2");
32
33 println!("{}", task.await);
34 });
35 println!("bye");
36}