use std::time::Instant;
pub type Recipient = (u64, Instant);
#[derive(Debug, Default)]
pub struct PublishRecord {
pub(crate) recipients: Vec<Recipient>,
pub(crate) appended_at: Option<Instant>,
}
impl PublishRecord {
#[must_use]
pub fn with_capacity(recipients: usize) -> Self {
Self {
recipients: Vec::with_capacity(recipients),
appended_at: None,
}
}
#[must_use]
pub fn capacity(&self) -> usize {
self.recipients.capacity()
}
#[must_use]
pub fn recipients(&self) -> &[Recipient] {
&self.recipients
}
#[must_use]
pub const fn appended_at(&self) -> Option<Instant> {
self.appended_at
}
pub fn clear(&mut self) {
self.recipients.clear();
self.appended_at = None;
}
}
pub fn recorded_now() -> Instant {
#[cfg(test)]
CLOCK_READS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
Instant::now()
}
#[cfg(test)]
pub static CLOCK_READS: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);