pub struct Announcement<T> { /* private fields */ }Expand description
The main announcement channel type that creates listeners.
This is the primary interface for creating listeners that will receive the announced value. It can be cloned cheaply to share across threads.
§Examples
use announcement::Announcement;
let (announcer, announcement) = Announcement::<i32>::new();
let listener1 = announcement.listener();
let listener2 = announcement.listener();
announcer.announce(42).unwrap();
assert_eq!(listener1.try_listen(), Some(42));
assert_eq!(listener2.try_listen(), Some(42));Implementations§
Source§impl<T: Clone + Send + Sync + 'static> Announcement<T>
impl<T: Clone + Send + Sync + 'static> Announcement<T>
Sourcepub fn new() -> (Announcer<T>, Self)
pub fn new() -> (Announcer<T>, Self)
Create a new announcement channel.
Returns a tuple of (Announcer, Announcement). The announcer is used to
broadcast the value once, and the announcement is used to create listeners.
§Examples
use announcement::Announcement;
let (announcer, announcement) = Announcement::<i32>::new();Sourcepub fn listener(&self) -> Listener<T>
pub fn listener(&self) -> Listener<T>
Create a new listener for this announcement.
Can be called before or after announcing. Can be called multiple times to create multiple independent listeners that will all receive the same value.
§Performance
O(1), performs 2 Arc clones (~10-20ns)
§Examples
use announcement::Announcement;
let (announcer, announcement) = Announcement::new();
let listener1 = announcement.listener();
let listener2 = announcement.listener();
announcer.announce(42).unwrap();
assert_eq!(listener1.try_listen(), Some(42));
assert_eq!(listener2.try_listen(), Some(42));Sourcepub fn is_announced(&self) -> bool
pub fn is_announced(&self) -> bool
Check if a value has been announced.
This is a non-blocking, lock-free operation.
§Performance
O(1), ~5-10ns
§Examples
use announcement::Announcement;
let (announcer, announcement) = Announcement::<i32>::new();
assert!(!announcement.is_announced());
announcer.announce(42).unwrap();
assert!(announcement.is_announced());Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Check if the announcer was closed without announcing.
Returns true if the announcer was explicitly closed or dropped without announcing.
This is a non-blocking, lock-free operation.
§Performance
O(1), ~5-10ns
§Examples
use announcement::Announcement;
let (announcer, announcement) = Announcement::<i32>::new();
assert!(!announcement.is_closed());
drop(announcer);
assert!(announcement.is_closed());Trait Implementations§
Source§impl<T: Clone> Clone for Announcement<T>
impl<T: Clone> Clone for Announcement<T>
Source§fn clone(&self) -> Announcement<T>
fn clone(&self) -> Announcement<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more