throttle

Macro throttle 

Source
macro_rules! throttle {
    ($duration:expr, || $expr:expr) => { ... };
}
Expand description

Throttles the execution of an expression to run at most once per specified duration.

Uses static variables with lazy initialization to track the last execution time. Thread-safe via atomic operations.

§Examples

use std::time::Duration;
use reth_tracing::throttle;

// Log at most once per second.
throttle!(Duration::from_secs(1), || {
    tracing::info!("This message is throttled");
});