Created
May 24, 2013 15:59
-
-
Save vsavkin/5644505 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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