mod read;
mod replace;
mod sync;
mod write;
pub use sync::SyncResult;
use std::collections::HashMap;
use std::sync::atomic::AtomicU64;
use arc_swap::ArcSwap;
use super::Entry;
#[cfg(feature = "events")]
use super::HoldEvent;
pub const DEFAULT_EVENT_CAPACITY: usize = 100;
pub struct Store<T> {
pub(crate) inner: ArcSwap<HashMap<String, Entry<T>>>,
pub(crate) version: AtomicU64,
#[cfg(feature = "events")]
pub(crate) events: tokio::sync::broadcast::Sender<HoldEvent<T>>,
}
impl<T> Store<T>
where
T: Clone + Send + Sync,
{
pub fn new() -> Self {
Self {
inner: ArcSwap::from_pointee(HashMap::new()),
version: AtomicU64::new(0),
#[cfg(feature = "events")]
events: tokio::sync::broadcast::channel(DEFAULT_EVENT_CAPACITY).0,
}
}
#[cfg(feature = "events")]
pub fn with_event_capacity(capacity: usize) -> Self {
Self {
inner: ArcSwap::from_pointee(HashMap::new()),
version: AtomicU64::new(0),
events: tokio::sync::broadcast::channel(capacity).0,
}
}
}
impl<T> Default for Store<T>
where
T: Clone + Send + Sync,
{
fn default() -> Self {
Self::new()
}
}