@@ -333,7 +333,7 @@ impl<A: Allocate> Worker<A> {
333333 /// worker.step_or_park(Some(Duration::from_secs(1)));
334334 /// });
335335 /// ```
336- pub fn step_or_park ( & mut self , duration : Option < Duration > ) -> bool {
336+ pub fn step_or_park ( & mut self , timeout : Option < Duration > ) -> bool {
337337
338338 { // Process channel events. Activate responders.
339339 let mut allocator = self . allocator . borrow_mut ( ) ;
@@ -362,28 +362,23 @@ impl<A: Allocate> Worker<A> {
362362 . borrow_mut ( )
363363 . advance ( ) ;
364364
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+ }
372374
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) ;
374378
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 ( ) ) ) ;
379381 }
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 ( ) ) ) ;
387382 }
388383 else { // Schedule active dataflows.
389384
0 commit comments