use reifydb_value::value::duration::Duration;
#[derive(Debug, Clone, Copy)]
pub struct Throttle(Duration);
impl Throttle {
pub fn new(duration: Duration) -> Self {
if duration.is_negative() {
panic!("throttle must not be negative");
}
Self(duration)
}
pub fn duration(&self) -> Duration {
self.0
}
}
#[derive(Debug, Clone, Copy)]
pub struct Linger(Duration);
impl Linger {
pub fn new(duration: Duration) -> Self {
if duration.is_negative() {
panic!("linger must not be negative");
}
Self(duration)
}
pub fn duration(&self) -> Duration {
self.0
}
}
#[derive(Debug, Clone)]
pub struct HydrationConfig {
pub enabled: bool,
pub max_rows: Option<u64>,
}
impl Default for HydrationConfig {
fn default() -> Self {
Self {
enabled: true,
max_rows: None,
}
}
}
#[derive(Debug, Clone, Default)]
pub struct SubscriptionConfig {
pub hydration: HydrationConfig,
pub throttle: Option<Throttle>,
pub linger: Option<Linger>,
}
#[derive(Debug, Clone)]
pub struct SubscribeItem<'a> {
pub rql: &'a str,
pub config: SubscriptionConfig,
}
impl<'a> SubscribeItem<'a> {
pub fn new(rql: &'a str, config: SubscriptionConfig) -> Self {
Self {
rql,
config,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
#[should_panic(expected = "throttle must not be negative")]
fn negative_throttle_panics_naming_the_knob() {
Throttle::new(Duration::from_seconds(-5).unwrap());
}
#[test]
#[should_panic(expected = "linger must not be negative")]
fn negative_linger_panics_naming_the_knob() {
Linger::new(Duration::from_seconds(-5).unwrap());
}
}