use std::sync::Arc;
use std::time::Duration;
use once_cell::sync::Lazy;
use tokio::sync::Mutex;
use tokio::time::sleep_until;
use tokio::time::Instant;
static RATE_LIMIT_NEXT_SPOT: Lazy<Arc<Mutex<Instant>>> =
Lazy::new(|| Arc::new(Mutex::new(Instant::now())));
pub(super) async fn wait_for_ratelimit() {
let rate_limit_clone = RATE_LIMIT_NEXT_SPOT.clone();
#[allow(clippy::await_holding_lock)]
let mut next_slot = rate_limit_clone.lock().await;
let deadline = *next_slot;
sleep_until(deadline).await;
*next_slot = Instant::now() + Duration::from_secs(1);
}