Skip to main content

throttle

Macro throttle 

Source
macro_rules! throttle {
    ($duration:expr, || $expr:expr) => { ... };
}
๐Ÿ‘ŽDeprecated:

no longer used by reth and scheduled for removal, copy the macro if you depend on it

Available on crate feature std only.
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");
});