Last active
September 12, 2023 15:56
-
-
Save MarinPostma/d625e16107020b4b42f5f1b8908c9e67 to your computer and use it in GitHub Desktop.
tokio run_until bug
This file contains hidden or 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
| use std::time::Duration; | |
| use tokio::task::LocalSet; | |
| fn main() { | |
| let mut builder = tokio::runtime::Builder::new_current_thread(); | |
| let tokio = builder.enable_time().start_paused(true).build().unwrap(); | |
| let local = LocalSet::new(); | |
| let fut = async move { | |
| tokio::task::spawn_blocking(move || { | |
| dbg!(); | |
| std::thread::sleep(Duration::from_secs(10)); | |
| dbg!(); | |
| }); | |
| dbg!(); | |
| }; | |
| local.spawn_local(fut); | |
| tokio.block_on(async { | |
| local.run_until(async { | |
| dbg!(); | |
| tokio::time::sleep(Duration::from_secs(1)).await; | |
| dbg!(); | |
| }).await; | |
| local.run_until(async { | |
| dbg!(); | |
| tokio::time::sleep(Duration::from_secs(1)).await; | |
| dbg!(); | |
| }).await; | |
| dbg!(); | |
| }); | |
| drop(tokio); | |
| dbg!(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment