debounceStream<S, T> function

StreamTransformer<S, T> debounceStream<S, T>(
  1. Duration duration
)

Debounces a stream, preventing it from triggering until duration has passed between events.

For example, if a stream of keypresses is debounced with a duration of 250 milliseconds, an event will only be triggered once the user has stopped typing for 250 milliseconds.

This is useful if you have a burst of events and only want to deal with the last event in the burst. Let's say you have a search box, and only want to fetch autocomplete suggestions after the user has finished typing. That's a situation where you'd debounce the keypress event stream.

Only the last event in a burst is triggered, and it will be triggered after duration has elapsed. So if you debounce a keypress stream with a duration of 1s, and there are three events at t=0s, t=0.1s, at t=0.2s, the first two events will be discarded and the last event will be triggered at t=1.2s.

Implementation

StreamTransformer<S, T> debounceStream<S, T>(Duration duration) =>
    RateLimitTransformer<S, T>(duration, debounce);