Skip to content

Instantly share code, notes, and snippets.

@vsavkin
Created May 24, 2013 15:59
Show Gist options
  • Save vsavkin/5644505 to your computer and use it in GitHub Desktop.
Save vsavkin/5644505 to your computer and use it in GitHub Desktop.
class Throttle<T> extends StreamEventTransformer<T,T> {
final duration;
Timer lastTimer;
Throttle(millis) :duration = new Duration(milliseconds : millis);
void handleData(T event, EventSink sink) {
if (lastTimer != null) {
lastTimer.cancel();
}
lastTimer = new Timer(duration, () => sink.add(event));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment