2
0
Fork 1
mirror of https://github.com/async-rs/async-std.git synced 2025-02-28 23:29:41 +00:00
async-std/examples/task-local.rs

20 lines
362 B
Rust
Raw Normal View History

2019-08-08 12:44:48 +00:00
//! Creates a task-local value.
#![feature(async_await)]
use std::cell::Cell;
use async_std::{task, task_local};
task_local! {
static VAR: Cell<i32> = Cell::new(1);
}
fn main() {
task::block_on(async {
println!("var = {}", VAR.with(|v| v.get()));
VAR.with(|v| v.set(2));
println!("var = {}", VAR.with(|v| v.get()));
})
}