Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
We should add a
The goal of this function is to limit the amount of items yielded per timeslice in a stream. This is usually considered a somewhat brute tool, but it does have its use and we should give people access to this.
// emit value every 1 second let s = stream::interval(Duration::from_secs(1)).enumerate(); // throttle for 2 seconds, emit latest value // in this case it means we skip two iterations, and let through the third let s = s.throttle(Duration::from_secs(2)); s.for_each(|(_, n)| dbg!(n)).await; // => 0 .. 3 .. 6 .. 9
@Wassasin hehe, yeah I wanted to add
@binarybana hmm, you might be right. I do think that dropping events is the right approach for any
I implemented the stream-throttle crate, which uses a backpressure approach.
It uses an intermediate
Perhaps some part of it could form the base for a solution. Just a thought!