A small throttle utility that collects items and provides a way to handle them after a configured delay. crates.io/crates/simple-throttle
Files
README.md

Simple Throttle #

A small throttle utility that collects items and invokes a handler after a configured delay. Works in both blocking and asynchronous contexts, enable the tokio feature for async support.

Example #

use simple_throttle::Throttle;
use std::time::Duration;

#[tokio::main]
async fn main() {
    let mut throttle: Throttle<u32> = Throttle::new(Duration::from_secs(1));
    throttle.push(1);

    throttle.wait_ready().await;

    throttle.trigger(|mut queue| async move {
        while let Some(item) = queue.pop_front() {
            println!("Item: {}", item);
        }
    }).await;
}