Last active
September 21, 2019 16:56
-
-
Save osa1/f6e60f00471eaaf6f5c11194df997271 to your computer and use it in GitHub Desktop.
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
[package] | |
name = "delay_test" | |
version = "0.1.0" | |
authors = ["Ömer Sinan Ağacan <[email protected]>"] | |
edition = "2018" | |
[dependencies] | |
tokio = { git = "https://github.com/tokio-rs/tokio.git", features = ["timer"] } | |
futures-preview = { version = "0.3.0-alpha.18", features = ["async-await", "nightly"] } | |
futures-util-preview = "0.3.0-alpha.18" |
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
delay_test git:(master) $ cargo run | |
Compiling delay_test v0.1.0 (/home/omer/rust/delay_test) | |
Finished dev [unoptimized + debuginfo] target(s) in 0.82s | |
Running `target/debug/delay_test` | |
done | |
main returns |
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 futures::select; | |
use std::time::Duration; | |
use tokio::timer; | |
fn main() { | |
let mut executor = tokio::runtime::current_thread::Runtime::new().unwrap(); | |
// let executor = tokio::runtime::Runtime::new().unwrap(); | |
executor.spawn(async { | |
let mut delay1 = timer::delay_for(Duration::from_secs(3)); | |
let mut delay2 = timer::delay_for(Duration::from_secs(3)); | |
select! { | |
() = delay1 => { | |
println!("delay 1"); | |
}, | |
() = delay2 => { | |
println!("delay 2"); | |
}, | |
complete => { | |
println!("done"); | |
} | |
} | |
}); | |
executor.run().unwrap(); | |
// executor.shutdown_on_idle(); | |
println!("main returns"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment