withTimeoutBetweenEvents method

Stream<T> withTimeoutBetweenEvents(
  1. Duration duration
)

Adds a timeout between events of the stream. If the time between two consecutive events exceeds the specified duration, a TimeoutBetweenEventsException will be added to the stream.

Example usage:

void main() {
  final stream = Stream<int>.periodic(const Duration(seconds: 2), (i) => i);

  const duration = Duration(seconds: 1);
  final timedStream = stream.withTimeoutBetweenEvents(duration);

  timedStream.listen(
    (data) {
        print('Received: $data');
    },
    onError: (error) {
        if (error is TimeoutBetweenEventsException) {
            print('Timeout occurred between events');
        }
    },
  );
}

Implementation

Stream<T> withTimeoutBetweenEvents(Duration duration) => transform(TimeoutBetweenEvents(duration: duration));