use crate::context::Receiver;
use crate::messages::Message;
use std::time::Duration;
pub struct StreamBuilder<T: Message> {
pub(super) receiver: Receiver<T>,
#[allow(clippy::type_complexity)]
pub(super) filter_fn: Option<Box<dyn Fn(&T) -> bool + Send + Sync>>,
#[allow(clippy::type_complexity)]
pub(super) map_fn: Option<Box<dyn Fn(T) -> T + Send + Sync>>,
pub(super) throttle_duration: Option<Duration>,
pub(super) debounce_duration: Option<Duration>,
pub(super) latest_only: bool,
#[allow(dead_code)]
pub(super) batch_size: Option<usize>,
#[allow(dead_code)]
pub(super) batch_timeout: Option<Duration>,
}
impl<T: Message + Send + 'static> StreamBuilder<T> {
pub fn new(receiver: Receiver<T>) -> Self {
Self {
receiver,
filter_fn: None,
map_fn: None,
throttle_duration: None,
debounce_duration: None,
latest_only: false,
batch_size: None,
batch_timeout: None,
}
}
crate::builder_setter!(
predicate, filter, filter_fn, Fn(&T) -> bool + Send + Sync + 'static
);
crate::builder_setter!(
into_some, throttle, throttle_duration, Duration
);
pub fn latest(mut self) -> Self {
self.latest_only = true;
self
}
crate::builder_setter!(
predicate, map, map_fn, Fn(T) -> T + Send + Sync + 'static
);
crate::builder_setter!(
into_some, debounce, debounce_duration, Duration
);
}