Skip to content

Commit 6d2a097

Browse files
authored
feat: Add an "is_notified" function (#48)
1 parent 38f6e7c commit 6d2a097

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,26 @@ impl<T> Event<T> {
205205
}
206206
}
207207

208+
/// Tell whether any listeners are currently notified.
209+
///
210+
/// # Examples
211+
///
212+
/// ```
213+
/// use event_listener::Event;
214+
///
215+
/// let event = Event::new();
216+
/// let listener = event.listen();
217+
/// assert!(!event.is_notified());
218+
///
219+
/// event.notify(1);
220+
/// assert!(event.is_notified());
221+
/// ```
222+
#[inline]
223+
pub fn is_notified(&self) -> bool {
224+
self.try_inner()
225+
.map_or(false, |inner| inner.notified.load(Ordering::Acquire) > 0)
226+
}
227+
208228
/// Returns a guard listening for a notification.
209229
///
210230
/// This method emits a `SeqCst` fence after registering a listener. For now, this method

0 commit comments

Comments
 (0)