use std::sync::{Arc, OnceLock};
use tokio::sync::Semaphore;
pub struct RateLimiter {
pub semaphore: Arc<Semaphore>,
pub skip_semaphore: bool,
}
impl RateLimiter {
pub fn unlimited() -> Arc<Self> {
static UNLIMITED: OnceLock<Arc<RateLimiter>> = OnceLock::new();
UNLIMITED
.get_or_init(|| {
Arc::new(Self {
semaphore: Arc::new(Semaphore::new(Semaphore::MAX_PERMITS)),
skip_semaphore: true,
})
})
.clone()
}
}