THROTTLING DART LIBRARY
contain "throttling" and "debouncing" classes
Using
See a demonstration of use at dartpad.dev
Throttling example
final thr = Throttling<void>(duration: const Duration(milliseconds: 200));
thr.throttle(() {print(' * 1');}); // print ' * 1'
await Future<void>.delayed(const Duration(milliseconds: 100));
thr.throttle(() {print(' * 2');});
await Future<void>.delayed(const Duration(milliseconds: 100));
thr.throttle(() {print(' * 3');}); // print ' * 3'
thr.close();
Debouncing example
final deb = Debouncing<void>(duration: const Duration(milliseconds: 200));
deb.debounce(() {print(' * 1');});
await Future<void>.delayed(const Duration(milliseconds: 100));
deb.debounce(() {print(' * 2');});
await Future<void>.delayed(const Duration(milliseconds: 100));
deb.debounce(() {print(' * 3');});
await Future<void>.delayed(const Duration(milliseconds: 200));
// print ' * 3'
deb.close();