@@ -476,11 +476,11 @@ pub(crate) mod futures_util {
476476 use core:: pin:: Pin ;
477477 use core:: task:: { Poll , RawWaker , RawWakerVTable , Waker } ;
478478 pub ( crate ) struct Selector <
479- A : Future < Output = ( ) > + Unpin ,
479+ A : Future < Output = bool > + Unpin ,
480480 B : Future < Output = ( ) > + Unpin ,
481481 C : Future < Output = ( ) > + Unpin ,
482482 D : Future < Output = ( ) > + Unpin ,
483- E : Future < Output = bool > + Unpin ,
483+ E : Future < Output = ( ) > + Unpin ,
484484 > {
485485 pub a : A ,
486486 pub b : B ,
@@ -490,28 +490,30 @@ pub(crate) mod futures_util {
490490 }
491491
492492 pub ( crate ) enum SelectorOutput {
493- A ,
493+ A ( bool ) ,
494494 B ,
495495 C ,
496496 D ,
497- E ( bool ) ,
497+ E ,
498498 }
499499
500500 impl <
501- A : Future < Output = ( ) > + Unpin ,
501+ A : Future < Output = bool > + Unpin ,
502502 B : Future < Output = ( ) > + Unpin ,
503503 C : Future < Output = ( ) > + Unpin ,
504504 D : Future < Output = ( ) > + Unpin ,
505- E : Future < Output = bool > + Unpin ,
505+ E : Future < Output = ( ) > + Unpin ,
506506 > Future for Selector < A , B , C , D , E >
507507 {
508508 type Output = SelectorOutput ;
509509 fn poll (
510510 mut self : Pin < & mut Self > , ctx : & mut core:: task:: Context < ' _ > ,
511511 ) -> Poll < SelectorOutput > {
512+ // Bias the selector so it first polls the sleeper future, allowing to exit immediately
513+ // if the flag is set.
512514 match Pin :: new ( & mut self . a ) . poll ( ctx) {
513- Poll :: Ready ( ( ) ) => {
514- return Poll :: Ready ( SelectorOutput :: A ) ;
515+ Poll :: Ready ( res ) => {
516+ return Poll :: Ready ( SelectorOutput :: A ( res ) ) ;
515517 } ,
516518 Poll :: Pending => { } ,
517519 }
@@ -534,8 +536,8 @@ pub(crate) mod futures_util {
534536 Poll :: Pending => { } ,
535537 }
536538 match Pin :: new ( & mut self . e ) . poll ( ctx) {
537- Poll :: Ready ( res ) => {
538- return Poll :: Ready ( SelectorOutput :: E ( res ) ) ;
539+ Poll :: Ready ( ( ) ) => {
540+ return Poll :: Ready ( SelectorOutput :: E ) ;
539541 } ,
540542 Poll :: Pending => { } ,
541543 }
@@ -1037,15 +1039,15 @@ where
10371039 ( false , false ) => FASTEST_TIMER ,
10381040 } ;
10391041 let fut = Selector {
1040- a : channel_manager . get_cm ( ) . get_event_or_persistence_needed_future ( ) ,
1041- b : chain_monitor . get_update_future ( ) ,
1042- c : om_fut ,
1043- d : lm_fut ,
1044- e : sleeper ( sleep_delay ) ,
1042+ a : sleeper ( sleep_delay ) ,
1043+ b : channel_manager . get_cm ( ) . get_event_or_persistence_needed_future ( ) ,
1044+ c : chain_monitor . get_update_future ( ) ,
1045+ d : om_fut ,
1046+ e : lm_fut ,
10451047 } ;
10461048 match fut. await {
1047- SelectorOutput :: A | SelectorOutput :: B | SelectorOutput :: C | SelectorOutput :: D => { } ,
1048- SelectorOutput :: E ( exit) => {
1049+ SelectorOutput :: B | SelectorOutput :: C | SelectorOutput :: D | SelectorOutput :: E => { } ,
1050+ SelectorOutput :: A ( exit) => {
10491051 if exit {
10501052 break ;
10511053 }
0 commit comments