use std::time::Duration;
use crate::Runtime;
#[derive(Clone, Debug)]
#[cfg_attr(feature = "config", derive(serde::Deserialize))]
pub struct PoolConfig {
pub max_size: usize,
#[cfg_attr(feature = "config", serde(default))]
pub timeouts: Timeouts,
#[cfg_attr(feature = "config", serde(skip))]
pub runtime: Runtime,
}
impl PoolConfig {
pub fn new(max_size: usize) -> Self {
Self {
max_size,
timeouts: Timeouts::default(),
runtime: Runtime::default(),
}
}
}
impl Default for PoolConfig {
fn default() -> Self {
Self::new(num_cpus::get_physical() * 4)
}
}
#[derive(Clone, Debug)]
#[cfg_attr(feature = "config", derive(serde::Deserialize))]
pub struct Timeouts {
pub wait: Option<Duration>,
pub create: Option<Duration>,
pub recycle: Option<Duration>,
}
impl Timeouts {
pub fn new() -> Self {
Self::default()
}
pub fn wait_millis(wait: u64) -> Self {
Self {
create: None,
wait: Some(Duration::from_millis(wait)),
recycle: None,
}
}
}
impl Default for Timeouts {
fn default() -> Self {
Self {
create: None,
wait: None,
recycle: None,
}
}
}