Skip to content

Commit 076c626

Browse files
committed
Add PeerManager::process_pending_events_async
1 parent 2920f03 commit 076c626

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lightning/src/events/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,9 +1885,11 @@ pub trait MessageSendEventsProvider {
18851885
///
18861886
/// Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
18871887
///
1888-
/// Implementations of this trait may also feature an async version of event handling, as shown with
1889-
/// [`ChannelManager::process_pending_events_async`] and
1890-
/// [`ChainMonitor::process_pending_events_async`].
1888+
/// Implementations of this trait may also feature an async version of event handling, as shown
1889+
/// with:
1890+
/// - [`ChannelManager::process_pending_events_async`]
1891+
/// - [`ChainMonitor::process_pending_events_async`]
1892+
/// - [`PeerManager::process_pending_events_async`]
18911893
///
18921894
/// # Requirements
18931895
///
@@ -1917,6 +1919,7 @@ pub trait MessageSendEventsProvider {
19171919
/// [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events
19181920
/// [`ChannelManager::process_pending_events_async`]: crate::ln::channelmanager::ChannelManager::process_pending_events_async
19191921
/// [`ChainMonitor::process_pending_events_async`]: crate::chain::chainmonitor::ChainMonitor::process_pending_events_async
1922+
/// [`PeerManager::process_pending_events_async`]: crate::ln::peer_handler::PeerManager::process_pending_events_async
19201923
pub trait EventsProvider {
19211924
/// Processes any events generated since the last call using the given event handler.
19221925
///

lightning/src/ln/peer_handler.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,6 +2478,19 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
24782478
let _ = self.message_handler.route_handler.handle_node_announcement(&msg);
24792479
self.forward_broadcast_msg(&*self.peers.read().unwrap(), &wire::Message::NodeAnnouncement(msg), None);
24802480
}
2481+
2482+
/// Processes any events asynchronously in the order they were generated since the last call
2483+
/// using the given event handler.
2484+
///
2485+
/// See the trait-level documentation of [`EventsProvider`] for requirements.
2486+
pub async fn process_pending_events_async<Future: core::future::Future, H: Fn(Event) -> Future>(
2487+
&self, handler: H
2488+
) {
2489+
let pending_events = core::mem::take(&mut *self.pending_events.lock().unwrap());
2490+
for event in pending_events {
2491+
handler(event).await;
2492+
}
2493+
}
24812494
}
24822495

24832496
fn is_gossip_msg(type_id: u16) -> bool {

0 commit comments

Comments
 (0)