New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stream throttling #8492
Comments
Is throttling by time the most useful approach? If it's because you only want to poll the output of a stream every <duration>, I'd just store the events in a variable, and read it from a repeating timer. So, what I'm asking is: Are you sure this is really a common need that belongs in the standard libary? Removed Type-Defect label. |
This comment was originally written by @seaneagan It is definitely useful for UI Event Streams. Here are some links to check out: http://benalman.com/projects/jquery-throttle-debounce-plugin/ I'd have to do a little more research on IO Stream throttling, as I don't have as much experience with that. |
This comment was originally written by @seaneagan more client side frameworks which support throttle and debounce: closure library: http://closure-library.googlecode.com/svn-history/r144/docs/class_goog_async_Throttle.html dojo plugd: https://github.com/phiggins42/plugd/blob/master/base.js#L507 lodash: http://lodash.com/docs#throttle |
This comment was originally written by @seaneagan http://stackoverflow.com/questions/15072071/streams-equivalent-to-observable-throttle |
This comment was originally written by @MarkBennett In reply to the first comment by lrn@google.com, I'm just curious if there are other examples of applications throttling by workload rather than time? Would a syntax like this work? Future lookUpDefinition(String word) { // Only the first event in the stream is processed // Only one event is processed within a five second period Debouncing really only makes sense to me in the context of a timer, so the syntax could look like this: // Wait for 200 milliseconds before calling this for the first time Given that throttle or debounce a stream seems like a common transformation in many UIs including it in the standard library would definately have value. I know the throttle and debounce functions are well used in Underscore for example. Thoughts? |
This comment was originally written by @seaneagan This is now implemented in the rate_limit package: |
This issue was originally filed by @seaneagan
It would be useful to be able to throttle Stream events. Something like:
/// Returns a Stream with the same events as this Stream, but the events never occur within [duration] of eachother
Stream<E> throttle(Duration duration);
There are cases where you want to discard the extra events which occur before the Duration is up, such as UI events, and other cases, such as IO where you generally want to just delay the extra events, so probably need either an optional boolean argument or two separate methods.
Example:
button.onClick.throttle(new Duration(seconds: 1)).then(react);
The text was updated successfully, but these errors were encountered: