Skip to content

Commit 118a658

Browse files
committed
add sweeper handler
1 parent c1c4679 commit 118a658

File tree

1 file changed

+18
-2
lines changed
  • lightning-background-processor/src

1 file changed

+18
-2
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ pub(crate) mod futures_util {
602602
}
603603
}
604604
#[cfg(feature = "futures")]
605-
use core::task;
605+
use core::{task, future::Future};
606606
#[cfg(feature = "futures")]
607607
use futures_util::{dummy_waker, OptionalSelector, Selector, SelectorOutput};
608608

@@ -992,6 +992,22 @@ impl BackgroundProcessor {
992992
}
993993
event_handler.handle_event(event)
994994
};
995+
let sweeper_handler = || {
996+
let mut fut = Box::pin(sweeper.regenerate_and_broadcast_spend_if_necessary_locked());
997+
let mut waker = dummy_waker();
998+
let mut ctx = task::Context::from_waker(&mut waker);
999+
match fut.as_mut().poll(&mut ctx) {
1000+
task::Poll::Ready(result) => {
1001+
if let Err(_) = result {
1002+
log_error!(logger, "Failed to sweep output")
1003+
}
1004+
},
1005+
task::Poll::Pending => {
1006+
// In a sync context, we can't wait for the future to complete.
1007+
debug_assert!(false);
1008+
},
1009+
}
1010+
};
9951011
define_run_body!(
9961012
persister,
9971013
chain_monitor,
@@ -1004,7 +1020,7 @@ impl BackgroundProcessor {
10041020
},
10051021
peer_manager,
10061022
gossip_sync,
1007-
sweeper,
1023+
sweeper_handler,
10081024
logger,
10091025
scorer,
10101026
stop_thread.load(Ordering::Acquire),

0 commit comments

Comments
 (0)