Created
April 30, 2021 18:15
-
-
Save glommer/4aa64061fa77d2770ac99a6753a11e12 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let keep_running = Rc::new(Cell::new(true)); | |
let kr = keep_running.clone(); // there are now two objects pointing to the same place | |
// the ownership of this copy is passed to the task. | |
let background_printer = Task::local(async move { | |
while kr.get() { | |
sleep(Duration::from_millis(100)).await; | |
} | |
}); | |
sleep(Duration::from_seconds(2)).await; | |
keep_running.set(false); | |
background_printer.await; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment