[−][src]Function tokio::task::spawn_local
ⓘImportant traits for JoinHandle<T>
pub fn spawn_local<F>(future: F) -> JoinHandle<F::Output> where
F: Future + 'static,
F::Output: 'static,
This is supported on
feature="rt-core"
and feature="rt-util"
only.Spawns a !Send
future on the local task set.
The spawned future will be run on the same thread that called spawn_local.
This may only be called from the context of a local task set.
Panics
- This function panics if called outside of a local task set.
Examples
use std::rc::Rc; use tokio::task; let unsend_data = Rc::new("my unsend data..."); let mut rt = Runtime::new().unwrap(); let local = task::LocalSet::new(); // Run the local task set. local.block_on(&mut rt, async move { let unsend_data = unsend_data.clone(); task::spawn_local(async move { println!("{}", unsend_data); // ... }).await.unwrap(); });