From dd89c4d786cc7614ec7952dfbe498c8e608edc16 Mon Sep 17 00:00:00 2001 From: jtnunley Date: Tue, 14 Mar 2023 09:33:54 -0700 Subject: [PATCH 1/2] Add an "is_notified" function --- src/lib.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index ec9d257..6a49ad6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -205,6 +205,26 @@ impl Event { } } + /// 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::Relaxed) > 0) + } + /// Returns a guard listening for a notification. /// /// This method emits a `SeqCst` fence after registering a listener. For now, this method From f298d36c566bfca8b4f54f0f34bb160ce5e761bd Mon Sep 17 00:00:00 2001 From: notgull Date: Sun, 2 Apr 2023 12:18:39 -0700 Subject: [PATCH 2/2] Change to Acquire ordering --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 6a49ad6..7884ff7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -222,7 +222,7 @@ impl Event { #[inline] pub fn is_notified(&self) -> bool { self.try_inner() - .map_or(false, |inner| inner.notified.load(Ordering::Relaxed) > 0) + .map_or(false, |inner| inner.notified.load(Ordering::Acquire) > 0) } /// Returns a guard listening for a notification.