use std::time::Duration;
#[derive(Debug, Clone)]
pub struct BackendConfig {
queue_depth: usize,
event_batch_size: usize,
spin_before_park: Duration,
default_timeout: Option<Duration>,
}
impl BackendConfig {
pub fn new() -> Self {
Self::default()
}
pub fn queue_depth(&self) -> usize {
self.queue_depth
}
pub fn event_batch_size(&self) -> usize {
self.event_batch_size
}
pub fn spin_before_park(&self) -> Duration {
self.spin_before_park
}
pub fn default_timeout(&self) -> Option<Duration> {
self.default_timeout
}
pub fn with_queue_depth(mut self, queue_depth: usize) -> Self {
self.queue_depth = queue_depth.max(1);
self
}
pub fn with_event_batch_size(mut self, batch: usize) -> Self {
self.event_batch_size = batch.max(1);
self
}
pub fn with_spin_before_park(mut self, duration: Duration) -> Self {
self.spin_before_park = duration;
self
}
pub fn with_default_timeout(mut self, timeout: Option<Duration>) -> Self {
self.default_timeout = timeout;
self
}
}
impl Default for BackendConfig {
fn default() -> Self {
Self {
queue_depth: 4096,
event_batch_size: 512,
spin_before_park: Duration::from_micros(50),
default_timeout: None,
}
}
}