@@ -331,7 +331,7 @@ impl<A: Allocate> Worker<A> {
331331 /// worker.step_or_park(Some(Duration::from_secs(1)));
332332 /// });
333333 /// ```
334- pub fn step_or_park ( & mut self , duration : Option < Duration > ) -> bool {
334+ pub fn step_or_park ( & mut self , timeout : Option < Duration > ) -> bool {
335335
336336 { // Process channel events. Activate responders.
337337 let mut allocator = self . allocator . borrow_mut ( ) ;
@@ -360,28 +360,23 @@ impl<A: Allocate> Worker<A> {
360360 . borrow_mut ( )
361361 . advance ( ) ;
362362
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+ }
370372
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) ;
372376
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 ( ) ) ) ;
377379 }
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 ( ) ) ) ;
385380 }
386381 else { // Schedule active dataflows.
387382
0 commit comments