@@ -38,6 +38,8 @@ use lightning::routing::router::Router;
38
38
use lightning:: routing:: scoring:: { Score , WriteableScore } ;
39
39
use lightning:: util:: logger:: Logger ;
40
40
use lightning:: util:: persist:: Persister ;
41
+ #[ cfg( feature = "std" ) ]
42
+ use lightning:: util:: wakers:: Sleeper ;
41
43
use lightning_rapid_gossip_sync:: RapidGossipSync ;
42
44
43
45
use core:: ops:: Deref ;
@@ -388,23 +390,32 @@ pub(crate) mod futures_util {
388
390
use core:: task:: { Poll , Waker , RawWaker , RawWakerVTable } ;
389
391
use core:: pin:: Pin ;
390
392
use core:: marker:: Unpin ;
391
- pub ( crate ) struct Selector < A : Future < Output =( ) > + Unpin , B : Future < Output =bool > + Unpin > {
393
+ pub ( crate ) struct Selector <
394
+ A : Future < Output =( ) > + Unpin , B : Future < Output =( ) > + Unpin , C : Future < Output =bool > + Unpin
395
+ > {
392
396
pub a : A ,
393
397
pub b : B ,
398
+ pub c : C ,
394
399
}
395
400
pub ( crate ) enum SelectorOutput {
396
- A , B ( bool ) ,
401
+ A , B , C ( bool ) ,
397
402
}
398
403
399
- impl < A : Future < Output =( ) > + Unpin , B : Future < Output =bool > + Unpin > Future for Selector < A , B > {
404
+ impl <
405
+ A : Future < Output =( ) > + Unpin , B : Future < Output =( ) > + Unpin , C : Future < Output =bool > + Unpin
406
+ > Future for Selector < A , B , C > {
400
407
type Output = SelectorOutput ;
401
408
fn poll ( mut self : Pin < & mut Self > , ctx : & mut core:: task:: Context < ' _ > ) -> Poll < SelectorOutput > {
402
409
match Pin :: new ( & mut self . a ) . poll ( ctx) {
403
410
Poll :: Ready ( ( ) ) => { return Poll :: Ready ( SelectorOutput :: A ) ; } ,
404
411
Poll :: Pending => { } ,
405
412
}
406
413
match Pin :: new ( & mut self . b ) . poll ( ctx) {
407
- Poll :: Ready ( res) => { return Poll :: Ready ( SelectorOutput :: B ( res) ) ; } ,
414
+ Poll :: Ready ( ( ) ) => { return Poll :: Ready ( SelectorOutput :: B ) ; } ,
415
+ Poll :: Pending => { } ,
416
+ }
417
+ match Pin :: new ( & mut self . c ) . poll ( ctx) {
418
+ Poll :: Ready ( res) => { return Poll :: Ready ( SelectorOutput :: C ( res) ) ; } ,
408
419
Poll :: Pending => { } ,
409
420
}
410
421
Poll :: Pending
@@ -514,11 +525,13 @@ where
514
525
gossip_sync, peer_manager, logger, scorer, should_break, {
515
526
let fut = Selector {
516
527
a: channel_manager. get_persistable_update_future( ) ,
517
- b: sleeper( Duration :: from_millis( 100 ) ) ,
528
+ b: chain_monitor. get_update_future( ) ,
529
+ c: sleeper( Duration :: from_millis( 100 ) ) ,
518
530
} ;
519
531
match fut. await {
520
532
SelectorOutput :: A => true ,
521
- SelectorOutput :: B ( exit) => {
533
+ SelectorOutput :: B => false ,
534
+ SelectorOutput :: C ( exit) => {
522
535
should_break = exit;
523
536
false
524
537
}
@@ -643,7 +656,10 @@ impl BackgroundProcessor {
643
656
define_run_body ! ( persister, chain_monitor, chain_monitor. process_pending_events( & event_handler) ,
644
657
channel_manager, channel_manager. process_pending_events( & event_handler) ,
645
658
gossip_sync, peer_manager, logger, scorer, stop_thread. load( Ordering :: Acquire ) ,
646
- channel_manager. get_persistable_update_future( ) . wait_timeout( Duration :: from_millis( 100 ) ) ,
659
+ Sleeper :: from_two_futures(
660
+ channel_manager. get_persistable_update_future( ) ,
661
+ chain_monitor. get_update_future( )
662
+ ) . wait_timeout( Duration :: from_millis( 100 ) ) ,
647
663
|_| Instant :: now( ) , |time: & Instant , dur| time. elapsed( ) . as_secs( ) > dur)
648
664
} ) ;
649
665
Self { stop_thread : stop_thread_clone, thread_handle : Some ( handle) }
0 commit comments