@@ -346,7 +346,7 @@ impl<A: Allocate> Worker<A> {
346346 /// worker.step_or_park(Some(Duration::from_secs(1)));
347347 /// });
348348 /// ```
349- pub fn step_or_park ( & mut self , duration : Option < Duration > ) -> bool {
349+ pub fn step_or_park ( & mut self , timeout : Option < Duration > ) -> bool {
350350
351351 { // Process channel events. Activate responders.
352352 let mut allocator = self . allocator . borrow_mut ( ) ;
@@ -375,28 +375,23 @@ impl<A: Allocate> Worker<A> {
375375 . borrow_mut ( )
376376 . advance ( ) ;
377377
378- // Consider parking only if we have no pending events, some dataflows, and a non-zero duration.
379- let empty_for = self . activations . borrow ( ) . empty_for ( ) ;
380- // Determine the minimum park duration, where `None` are an absence of a constraint.
381- let delay = match ( duration, empty_for) {
382- ( Some ( x) , Some ( y) ) => Some ( std:: cmp:: min ( x, y) ) ,
383- ( x, y) => x. or ( y) ,
384- } ;
378+ if self . activations . borrow ( ) . is_idle ( ) {
379+ // If the timeout is zero, don't bother trying to park.
380+ // More generally, we could put some threshold in here.
381+ if timeout != Some ( Duration :: new ( 0 , 0 ) ) {
382+ // Log parking and flush log.
383+ if let Some ( l) = self . logging ( ) . as_mut ( ) {
384+ l. log ( crate :: logging:: ParkEvent :: park ( timeout) ) ;
385+ l. flush ( ) ;
386+ }
385387
386- if delay != Some ( Duration :: new ( 0 , 0 ) ) {
388+ // We have just drained `allocator.events()` up above;
389+ // otherwise we should first check it for emptiness.
390+ self . activations . borrow ( ) . park_timeout ( timeout) ;
387391
388- // Log parking and flush log.
389- if let Some ( l) = self . logging ( ) . as_mut ( ) {
390- l. log ( crate :: logging:: ParkEvent :: park ( delay) ) ;
391- l. flush ( ) ;
392+ // Log return from unpark.
393+ self . logging ( ) . as_mut ( ) . map ( |l| l. log ( crate :: logging:: ParkEvent :: unpark ( ) ) ) ;
392394 }
393-
394- self . allocator
395- . borrow ( )
396- . await_events ( delay) ;
397-
398- // Log return from unpark.
399- self . logging ( ) . as_mut ( ) . map ( |l| l. log ( crate :: logging:: ParkEvent :: unpark ( ) ) ) ;
400395 }
401396 else { // Schedule active dataflows.
402397
0 commit comments