Skip to content

Instantly share code, notes, and snippets.

@glommer
Created May 3, 2021 19:26
Show Gist options
  • Save glommer/33c2d0c3c50bd44eb2ab050fb142b4f5 to your computer and use it in GitHub Desktop.
Save glommer/33c2d0c3c50bd44eb2ab050fb142b4f5 to your computer and use it in GitHub Desktop.
async fn some_async_function() {
let shared = Rc::new(Cell::new(0));
let s = shared.clone();
let x = Task::local(async move {
do_async_work(s).await; // used a Clone of shared state
}); // <== task starts executing here
do_more_work(shared); // <== may be still background executing here
x.await; // <== but is surely done here.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment