@@ -8,7 +8,7 @@ use std::time::Duration;
8
8
use actix_rt:: time:: { sleep, Sleep } ;
9
9
use actix_rt:: { spawn, Arbiter } ;
10
10
use actix_utils:: counter:: Counter ;
11
- use futures_core:: future:: LocalBoxFuture ;
11
+ use futures_core:: { future:: LocalBoxFuture , ready } ;
12
12
use log:: { error, info, trace} ;
13
13
use tokio:: sync:: mpsc:: { unbounded_channel, UnboundedReceiver , UnboundedSender } ;
14
14
use tokio:: sync:: oneshot;
@@ -263,19 +263,16 @@ impl ServerWorker {
263
263
}
264
264
265
265
fn shutdown ( & mut self , force : bool ) {
266
- if force {
267
- self . services . iter_mut ( ) . for_each ( |srv| {
268
- if srv. status == WorkerServiceStatus :: Available {
269
- srv. status = WorkerServiceStatus :: Stopped ;
270
- }
271
- } ) ;
272
- } else {
273
- self . services . iter_mut ( ) . for_each ( move |srv| {
274
- if srv. status == WorkerServiceStatus :: Available {
275
- srv. status = WorkerServiceStatus :: Stopping ;
276
- }
266
+ self . services
267
+ . iter_mut ( )
268
+ . filter ( |srv| srv. status == WorkerServiceStatus :: Available )
269
+ . for_each ( |srv| {
270
+ srv. status = if force {
271
+ WorkerServiceStatus :: Stopped
272
+ } else {
273
+ WorkerServiceStatus :: Stopping
274
+ } ;
277
275
} ) ;
278
- }
279
276
}
280
277
281
278
fn check_readiness ( & mut self , cx : & mut Context < ' _ > ) -> Result < bool , ( Token , usize ) > {
@@ -466,16 +463,15 @@ impl Future for ServerWorker {
466
463
}
467
464
}
468
465
469
- match Pin :: new ( & mut self . rx ) . poll_recv ( cx) {
466
+ match ready ! ( Pin :: new( & mut self . rx) . poll_recv( cx) ) {
470
467
// handle incoming io stream
471
- Poll :: Ready ( Some ( WorkerCommand ( msg) ) ) => {
468
+ Some ( WorkerCommand ( msg) ) => {
472
469
let guard = self . conns . get ( ) ;
473
470
let _ = self . services [ msg. token . 0 ]
474
471
. service
475
472
. call ( ( Some ( guard) , msg. io ) ) ;
476
473
}
477
- Poll :: Pending => return Poll :: Pending ,
478
- Poll :: Ready ( None ) => return Poll :: Ready ( ( ) ) ,
474
+ None => return Poll :: Ready ( ( ) ) ,
479
475
} ;
480
476
} ,
481
477
}
0 commit comments