Skip to content

Commit

Permalink
feat: Add an "is_notified" function (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
notgull authored May 14, 2023
1 parent 38f6e7c commit 6d2a097
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,26 @@ impl<T> Event<T> {
}
}

/// Tell whether any listeners are currently notified.
///
/// # Examples
///
/// ```
/// use event_listener::Event;
///
/// let event = Event::new();
/// let listener = event.listen();
/// assert!(!event.is_notified());
///
/// event.notify(1);
/// assert!(event.is_notified());
/// ```
#[inline]
pub fn is_notified(&self) -> bool {
self.try_inner()
.map_or(false, |inner| inner.notified.load(Ordering::Acquire) > 0)
}

/// Returns a guard listening for a notification.
///
/// This method emits a `SeqCst` fence after registering a listener. For now, this method
Expand Down

0 comments on commit 6d2a097

Please sign in to comment.