debounce method

Stream<T> debounce(
  1. Stream window(
    1. T event
    )
)

Transforms a Stream so that will only emit items from the source sequence if a window has completed, without the source sequence emitting another item.

This window is created after the last debounced event was emitted. You can use the value of the last debounced event to determine the length of the next window.

A window is open until the first window event emits.

debounce filters out items emitted by the source Stream that are rapidly followed by another emitted item.

Interactive marble diagram

Example

Stream.fromIterable([1, 2, 3, 4])
  .debounce((_) => TimerStream(true, Duration(seconds: 1)))
  .listen(print); // prints 4

Implementation

Stream<T> debounce(Stream Function(T event) window) =>
    DebounceStreamTransformer<T>(window).bind(this);