Closed
Description
We should add a Stream::throttle
method as "unstable", similar to RxJs's throttle
function.
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.
Examples
// 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