pub struct ObservationSender { /* private fields */ }Expand description
The providers’ half of the bounded queue to the manager: a send that would wait is a drop,
counted in the counter the manager reports as overflow.
use majordomus_cli::mesh::provider::{Observation, ObservationSender};
use majordomus_cli::mesh::MeshSource;
let (tx, rx) = ObservationSender::bounded(1);
let seen = || Observation { source: MeshSource::UdpMulticast, path: "x".into(), bytes: vec![] };
assert!(tx.send(seen()));
assert!(!tx.send(seen()), "the queue is full: dropped");
assert_eq!(tx.dropped(), 1);
assert!(rx.try_recv().is_ok());Implementations§
Source§impl ObservationSender
impl ObservationSender
Sourcepub fn bounded(capacity: usize) -> (Self, Receiver<Observation>)
pub fn bounded(capacity: usize) -> (Self, Receiver<Observation>)
A queue of capacity, with a counter of its own.
use majordomus_cli::mesh::provider::{Observation, ObservationSender};
use majordomus_cli::mesh::MeshSource;
let (tx, rx) = ObservationSender::bounded(2);
assert!(tx.send(Observation { source: MeshSource::UdpMulticast, path: "a".into(), bytes: vec![] }));
assert!(rx.try_recv().is_ok());Sourcepub fn counting(
capacity: usize,
dropped: Arc<AtomicU64>,
) -> (Self, Receiver<Observation>)
pub fn counting( capacity: usize, dropped: Arc<AtomicU64>, ) -> (Self, Receiver<Observation>)
A queue of capacity whose drops land in dropped.
use majordomus_cli::mesh::provider::{Observation, ObservationSender};
use majordomus_cli::mesh::MeshSource;
use std::sync::{atomic::{AtomicU64, Ordering}, Arc};
let counter = Arc::new(AtomicU64::new(0));
let (tx, _rx) = ObservationSender::counting(0, Arc::clone(&counter));
tx.send(Observation { source: MeshSource::UdpMulticast, path: "a".into(), bytes: vec![] });
assert_eq!(counter.load(Ordering::Relaxed), 1, "a queue of none drops everything, counted");Sourcepub fn send(&self, observation: Observation) -> bool
pub fn send(&self, observation: Observation) -> bool
Hand one observation over without waiting; false when it was dropped or nobody reads.
use majordomus_cli::mesh::provider::{Observation, ObservationSender};
use majordomus_cli::mesh::MeshSource;
let (tx, rx) = ObservationSender::bounded(1);
drop(rx);
assert!(!tx.send(Observation { source: MeshSource::UdpMulticast, path: "a".into(), bytes: vec![] }));
assert_eq!(tx.dropped(), 0, "nobody reading is not a drop");Trait Implementations§
Source§impl Clone for ObservationSender
impl Clone for ObservationSender
Source§fn clone(&self) -> ObservationSender
fn clone(&self) -> ObservationSender
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ObservationSender
impl RefUnwindSafe for ObservationSender
impl Send for ObservationSender
impl Sync for ObservationSender
impl Unpin for ObservationSender
impl UnsafeUnpin for ObservationSender
impl UnwindSafe for ObservationSender
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more