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