Skip to content

seaneagan/rate_limit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rate_limit

Build Status

Provides the following StreamTransformers to limit the rate at which a Stream emits events.

##Throttler

Enforces a wait period between events.

// Avoid excessively updating the position while scrolling.
window.onScroll
 .transform(new Throttler(const Duration(milliseconds: 100)))
 .forEach(updatePosition);
 
// Execute `renewToken` on click, but not more than once every 5 minutes.
querySelector('.interactive').onClick
 .transform(new Throttler(const Duration(minutes: 5), trailing: false))
 .forEach(renewToken);

##Debouncer

Enforces a quiet wait period between events.

// Avoid costly calculations while the window size is in flux.
window.onResize
 .transform(new Debouncer(const Duration(milliseconds: 150)))
 .forEach(calculateLayout);

// Execute `sendMail` on click, debouncing subsequent calls.
querySelector('#postbox').onClick
 .transform(new Debouncer(const Duration(milliseconds: 300), leading: true, trailing: false))
 .forEach(sendMail);

// Ensure `batchLog` is executed once after 1 second of debounced calls.
var source = new EventSource('/stream');
source.onMessage
 .transform(new Debouncer(const Duration(milliseconds: 250), maxWait: const Duration(seconds: 1)))
 .forEach(batchLog);

Inspired by lodash's throttle and debounce.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages