Skip to content

Commit 2bd85dd

Browse files
committed
delete channel for sleep
1 parent 53a3072 commit 2bd85dd

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

chapter4/src/4_5/main.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@ use tokio::time::{self, Duration};
55
async fn main() {
66
let wait_sec = 5;
77
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-
});
8+
let sleep = time::sleep(Duration::from_secs(wait_sec));
9+
tokio::pin!(sleep);
1410

1511
loop {
1612
tokio::select! {
17-
_ = &mut sleep_rx => {
13+
_ = &mut sleep => {
1814
println!("{} secondes elapsed", wait_sec);
1915
break;
2016
}

0 commit comments

Comments
 (0)