File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -522,6 +522,36 @@ impl EventListener {
522522 self . wait_internal ( Some ( deadline) )
523523 }
524524
525+ /// Drop this listener and discard its notification (if any) without notifying another
526+ /// active listener.
527+ ///
528+ /// Returns `true` if a notification was discarded.
529+ ///
530+ /// # Examples
531+ /// ```
532+ /// use event_listener::Event;
533+ ///
534+ /// let event = Event::new();
535+ /// let listener1 = event.listen();
536+ /// let listener2 = event.listen();
537+ ///
538+ /// event.notify(1);
539+ ///
540+ /// assert!(listener1.discard());
541+ /// assert!(!listener2.discard());
542+ /// ```
543+ pub fn discard ( mut self ) -> bool {
544+ // If this listener has never picked up a notification...
545+ if let Some ( entry) = self . entry . take ( ) {
546+ let mut list = self . inner . lock ( ) ;
547+ // Remove the listener from the list and return `true` if it was notified.
548+ if let State :: Notified ( _) = list. remove ( entry, self . inner . cache_ptr ( ) ) {
549+ return true ;
550+ }
551+ }
552+ false
553+ }
554+
525555 /// Returns `true` if this listener listens to the given `Event`.
526556 ///
527557 /// # Examples
You can’t perform that action at this time.
0 commit comments