#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct BatchingOptions {
pub message_count_threshold: u32,
pub byte_threshold: u32,
pub delay_threshold: std::time::Duration,
}
impl BatchingOptions {
pub fn new() -> Self {
Self::default()
}
pub fn set_message_count_threshold<V: Into<u32>>(mut self, v: V) -> Self {
self.message_count_threshold = v.into();
self
}
pub(crate) fn set_byte_threshold<V: Into<u32>>(mut self, v: V) -> Self {
self.byte_threshold = v.into();
self
}
pub fn set_delay_threshold<V: Into<std::time::Duration>>(mut self, v: V) -> Self {
self.delay_threshold = v.into();
self
}
}
impl std::default::Default for BatchingOptions {
fn default() -> Self {
Self {
message_count_threshold: 100_u32,
byte_threshold: 1_000_000_u32, delay_threshold: std::time::Duration::from_millis(10),
}
}
}
#[cfg(test)]
mod tests {
use super::BatchingOptions;
#[tokio::test]
async fn batching_options() -> anyhow::Result<()> {
let options = BatchingOptions::new()
.set_byte_threshold(1_234_u32)
.set_message_count_threshold(123_u32)
.set_delay_threshold(std::time::Duration::from_millis(12));
assert_eq!(options.byte_threshold, 1_234_u32);
assert_eq!(options.message_count_threshold, 123_u32);
assert_eq!(
options.delay_threshold,
std::time::Duration::from_millis(12)
);
Ok(())
}
}