expression
Schedule local work before driving LocalSet
Queue a task on a LocalSet and drive that set. Awaiting the set waits for its local tasks to finish. A local task still needs owned or sufficiently long-lived captures. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): 17 Common mistake: Using a borrowed stack local merely because the task cannot move threads.
Formal Syntax & Structure
rust syntaxrust
local.spawn_local(future); local.awaitWorking Example
Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() { let local = tokio::task::LocalSet::new(); let value = std::rc::Rc::new(17); let task = local.spawn_local(async move { *value }); local.await; println!("{}", task.await.unwrap());}