Skip to content

Commit 15038d4

Browse files
committed
Make Notifier pub to allow it being used outside of lightning
1 parent 4489ae0 commit 15038d4

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

lightning/src/util/wakers.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,29 @@ use core::pin::Pin;
3030
use core::task::{Context, Poll};
3131

3232
/// Used to signal to one of many waiters that the condition they're waiting on has happened.
33-
pub(crate) struct Notifier {
33+
///
34+
/// This is usually used by LDK objects such as [`ChannelManager`] or [`PeerManager`] to signal to
35+
/// the background processor that it should wake up and process pending events.
36+
///
37+
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
38+
/// [`PeerManager`]: crate::ln::peer_handler::PeerManager
39+
pub struct Notifier {
3440
notify_pending: Mutex<(bool, Option<Arc<Mutex<FutureState>>>)>,
3541
}
3642

3743
impl Notifier {
38-
pub(crate) fn new() -> Self {
44+
/// Constructs a new notifier.
45+
pub fn new() -> Self {
3946
Self { notify_pending: Mutex::new((false, None)) }
4047
}
4148

4249
/// Wake waiters, tracking that wake needs to occur even if there are currently no waiters.
43-
pub(crate) fn notify(&self) {
50+
///
51+
/// We deem the notification successful either directly after any callbacks were made, or after
52+
/// the user [`poll`]ed a previously-completed future.
53+
///
54+
/// [`poll`]: core::future::Future::poll
55+
pub fn notify(&self) {
4456
let mut lock = self.notify_pending.lock().unwrap();
4557
if let Some(future_state) = &lock.1 {
4658
if complete_future(future_state) {
@@ -52,7 +64,7 @@ impl Notifier {
5264
}
5365

5466
/// Gets a [`Future`] that will get woken up with any waiters
55-
pub(crate) fn get_future(&self) -> Future {
67+
pub fn get_future(&self) -> Future {
5668
let mut lock = self.notify_pending.lock().unwrap();
5769
let mut self_idx = 0;
5870
if let Some(existing_state) = &lock.1 {

0 commit comments

Comments
 (0)