@@ -482,6 +482,9 @@ pub(crate) mod futures_util {
482482 pub ( crate ) fn set_a ( & mut self , fut : A ) {
483483 self . a = JoinerResult :: Pending ( Some ( fut) ) ;
484484 }
485+ pub ( crate ) fn set_a_res ( & mut self , res : Result < ( ) , E > ) {
486+ self . a = JoinerResult :: Ready ( res) ;
487+ }
485488 pub ( crate ) fn set_b ( & mut self , fut : B ) {
486489 self . b = JoinerResult :: Pending ( Some ( fut) ) ;
487490 }
@@ -937,7 +940,20 @@ where
937940 . await
938941 } ;
939942 // TODO: Once our MSRV is 1.68 we should be able to drop the Box
940- futures. set_a ( Box :: pin ( fut) ) ;
943+ let mut fut = Box :: pin ( fut) ;
944+
945+ // Because persisting the ChannelManager is important to avoid accidental
946+ // force-closures, go ahead and poll the future once before we do slightly more
947+ // CPU-intensive tasks in the form of NetworkGraph pruning or scorer time-stepping
948+ // below. This will get it moving but won't block us for too long if the underlying
949+ // future is actually async.
950+ use core:: future:: Future ;
951+ let mut waker = dummy_waker ( ) ;
952+ let mut ctx = task:: Context :: from_waker ( & mut waker) ;
953+ match core:: pin:: Pin :: new ( & mut fut) . poll ( & mut ctx) {
954+ task:: Poll :: Ready ( res) => futures. set_a_res ( res) ,
955+ task:: Poll :: Pending => futures. set_a ( fut) ,
956+ }
941957
942958 log_trace ! ( logger, "Done persisting ChannelManager." ) ;
943959 }
0 commit comments