rate_limit_acquire

Function rate_limit_acquire 

Source
pub async fn rate_limit_acquire(rl: &RequestRateLimit)
Expand description

Sleep until a request slot is available within the rolling window, then record the slot.

If the window is full the function sleeps until the oldest in-window entry expires (capped at config.max_delay_ms). The Mutex guard is dropped before every .await call to preserve Send bounds.

ยงExample

use stygian_graph::adapters::graphql_rate_limit::{
    RateLimitConfig, RequestRateLimit, rate_limit_acquire,
};
use std::time::Duration;

let rl = RequestRateLimit::new(RateLimitConfig {
    max_requests: 2,
    ..Default::default()
});
rate_limit_acquire(&rl).await;
rate_limit_acquire(&rl).await;
// Third call blocks until the window rolls forward.