File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,10 @@ path = "src/4_2_5/main.rs"
26
26
name = " 4_3_1"
27
27
path = " src/4_3_1/main.rs"
28
28
29
+ [[bin ]]
30
+ name = " 4_5"
31
+ path = " src/4_5/main.rs"
32
+
29
33
[dependencies ]
30
34
lib = { path = " ../lib" }
31
35
tokio = { version = " 1.5.0" , features = [" full" ] }
Original file line number Diff line number Diff line change
1
+ use tokio:: time:: { self , Duration } ;
2
+
3
+ // tokio::time::sleepを使って、決まった時間を図るタイマーを作る
4
+ #[ tokio:: main]
5
+ async fn main ( ) {
6
+ let wait_sec = 5 ;
7
+ let ( _, mut wait) = tokio:: sync:: oneshot:: channel :: < ( ) > ( ) ;
8
+ let sleep = time:: sleep ( Duration :: from_secs ( wait_sec) ) ;
9
+ tokio:: pin!( sleep) ;
10
+
11
+ loop {
12
+ tokio:: select! {
13
+ _ = & mut sleep => {
14
+ println!( "{} secondes elapsed" , wait_sec) ;
15
+ break ;
16
+ }
17
+ _ = & mut wait => { }
18
+ }
19
+ }
20
+ }
You can’t perform that action at this time.
0 commit comments