Published 2025-09-03
Private port of rate_limit: 0.1.0 that was abandoned.
HH.
Enforces a wait period between events.
// Avoid excessively updating the position while scrolling.
window.onScroll
.transform(HHThrottler(const Duration(milliseconds: 100)))
.forEach(updatePosition);
// Execute `renewToken` on click, but not more than once every 5 minutes.
querySelector('.interactive').onClick
.transform(HHThrottler(const Duration(minutes: 5), trailing: false))
.forEach(renewToken);
Enforces a quiet wait period between events.
// Avoid costly calculations while the window size is in flux.
window.onResize
.transform(HHDebouncer(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 = EventSource('/stream');
source.onMessage
.transform(HHDebouncer(const Duration(milliseconds: 250), maxWait: const Duration(seconds: 1)))
.forEach(batchLog);