@@ -331,7 +331,7 @@ impl<A: Allocate> Worker<A> {
331
331
/// worker.step_or_park(Some(Duration::from_secs(1)));
332
332
/// });
333
333
/// ```
334
- pub fn step_or_park ( & mut self , duration : Option < Duration > ) -> bool {
334
+ pub fn step_or_park ( & mut self , timeout : Option < Duration > ) -> bool {
335
335
336
336
{ // Process channel events. Activate responders.
337
337
let mut allocator = self . allocator . borrow_mut ( ) ;
@@ -360,28 +360,23 @@ impl<A: Allocate> Worker<A> {
360
360
. borrow_mut ( )
361
361
. advance ( ) ;
362
362
363
- // Consider parking only if we have no pending events, some dataflows, and a non-zero duration.
364
- let empty_for = self . activations . borrow ( ) . empty_for ( ) ;
365
- // Determine the minimum park duration, where `None` are an absence of a constraint.
366
- let delay = match ( duration, empty_for) {
367
- ( Some ( x) , Some ( y) ) => Some ( std:: cmp:: min ( x, y) ) ,
368
- ( x, y) => x. or ( y) ,
369
- } ;
363
+ if self . activations . borrow ( ) . is_idle ( ) {
364
+ // If the timeout is zero, don't bother trying to park.
365
+ // More generally, we could put some threshold in here.
366
+ if timeout != Some ( Duration :: new ( 0 , 0 ) ) {
367
+ // Log parking and flush log.
368
+ if let Some ( l) = self . logging ( ) . as_mut ( ) {
369
+ l. log ( crate :: logging:: ParkEvent :: park ( timeout) ) ;
370
+ l. flush ( ) ;
371
+ }
370
372
371
- if delay != Some ( Duration :: new ( 0 , 0 ) ) {
373
+ // We have just drained `allocator.events()` up above;
374
+ // otherwise we should first check it for emptiness.
375
+ self . activations . borrow ( ) . park_timeout ( timeout) ;
372
376
373
- // Log parking and flush log.
374
- if let Some ( l) = self . logging ( ) . as_mut ( ) {
375
- l. log ( crate :: logging:: ParkEvent :: park ( delay) ) ;
376
- l. flush ( ) ;
377
+ // Log return from unpark.
378
+ self . logging ( ) . as_mut ( ) . map ( |l| l. log ( crate :: logging:: ParkEvent :: unpark ( ) ) ) ;
377
379
}
378
-
379
- self . allocator
380
- . borrow ( )
381
- . await_events ( delay) ;
382
-
383
- // Log return from unpark.
384
- self . logging ( ) . as_mut ( ) . map ( |l| l. log ( crate :: logging:: ParkEvent :: unpark ( ) ) ) ;
385
380
}
386
381
else { // Schedule active dataflows.
387
382
0 commit comments