We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 53a3072 commit 2bd85ddCopy full SHA for 2bd85dd
chapter4/src/4_5/main.rs
@@ -5,16 +5,12 @@ use tokio::time::{self, Duration};
5
async fn main() {
6
let wait_sec = 5;
7
let (_, mut wait) = tokio::sync::oneshot::channel::<()>();
8
- let (sleep_tx, mut sleep_rx) = tokio::sync::oneshot::channel();
9
-
10
- tokio::spawn(async move {
11
- time::sleep(Duration::from_secs(wait_sec)).await;
12
- sleep_tx.send("done").unwrap();
13
- });
+ let sleep = time::sleep(Duration::from_secs(wait_sec));
+ tokio::pin!(sleep);
14
15
loop {
16
tokio::select! {
17
- _ = &mut sleep_rx => {
+ _ = &mut sleep => {
18
println!("{} secondes elapsed", wait_sec);
19
break;
20
}
0 commit comments