File tree 1 file changed +11
-10
lines changed
1 file changed +11
-10
lines changed Original file line number Diff line number Diff line change @@ -12,13 +12,8 @@ async fn worker(name: u64) {
12
12
let mut counter = 0 ;
13
13
loop {
14
14
let result = tokio:: select! {
15
- _ = guard. wait( ) => None ,
16
- r = do_work( name) => Some ( r) ,
17
- } ;
18
-
19
- let result = match result {
20
- None => break ,
21
- Some ( x) => x,
15
+ r = do_work( name) => r,
16
+ _ = guard. wait( ) => break ,
22
17
} ;
23
18
24
19
counter += result;
@@ -34,16 +29,22 @@ async fn worker(name: u64) {
34
29
}
35
30
36
31
async fn important_worker ( ) {
37
- let _guard = elegant_departure:: get_shutdown_guard ( ) . shutdown_on_drop ( ) ;
32
+ let guard = elegant_departure:: get_shutdown_guard ( ) . shutdown_on_drop ( ) ;
38
33
39
- // Do some important work.
40
34
for i in 0 .. {
41
- sleep ( Duration :: from_secs ( 1 ) ) . await ;
35
+ // Do some important work and wait for the shutdown.
36
+ tokio:: select! {
37
+ _ = sleep( Duration :: from_secs( 1 ) ) => { } ,
38
+ _ = guard. wait( ) => break ,
39
+ } ;
40
+
42
41
if i == 5 {
43
42
panic ! ( "Oh no an unexpected crash in the important worker!" ) ;
44
43
}
45
44
println ! ( "[important_worker] Did some important work" ) ;
46
45
}
46
+
47
+ println ! ( "[important_worker] Important worker is shutting down" ) ;
47
48
}
48
49
49
50
#[ tokio:: main]
You can’t perform that action at this time.
0 commit comments