At the moment, there is no such method in streams. A request for a raise was requested, you can send a question 8492 .
However, you can do this with the where method. In the following example, I defined the ThrottleFilter class to ignore events for a given duration:
import 'dart:async'; class ThrottleFilter<T> { DateTime lastEventDateTime = null; final Duration duration; ThrottleFilter(this.duration); bool call(T e) { final now = new DateTime.now(); if (lastEventDateTime == null || now.difference(lastEventDateTime) > duration) { lastEventDateTime = now; return true; } return false; } } main() { final sc = new StreamController<int>(); final stream = sc.stream; // filter stream with ThrottleFilter stream.where(new ThrottleFilter<int>(const Duration(seconds: 10)).call) .listen(print); // send ints to stream every second, but ThrottleFilter will give only one int // every 10 sec. int i = 0; new Timer.repeating(const Duration(seconds:1), (t) { sc.add(i++); }); }
source share