slowly 0.3.1
slowly: ^0.3.1 copied to clipboard
Debouncing & Throttling: A lightweight Dart package for easily debouncing and throttling function calls to control execution frequency.
Features #
-
debounce
-
throttle
Getting started #
Usage #
import 'package:slowly/slowly.dart';
main() async {
/// <String>: tag type
final sly = Slowly<String>();
foo() {
print('foo func');
return 'foo!';
}
/// debounce
/// need 'await'
final fnFoo = await sly.debounce(
'foo',
foo,
duration: const Duration(milliseconds: 100),
);
if (fnFoo == null) return; // if locked, fnFoo will be null
final r = fnFoo();
print('debounce result: $r');
/// throttle
/// not need 'await'
final fnFoo2 = sly.throttle(
'bar',
foo,
duration: const Duration(milliseconds: 100),
);
if (fnFoo2 == null) return; // if locked, fnFoo will be null
final r2 = fnFoo2();
print('throttle result: $r2');
}