mirror of
https://github.com/zapstore/zapstore.git
synced 2026-10-05 20:48:24 +00:00
17 lines
335 B
Dart
17 lines
335 B
Dart
import 'dart:async';
|
|
|
|
const _debounceTime = 1200;
|
|
Timer? timer;
|
|
final acc = [];
|
|
|
|
void debounce<T>(T input, Future Function(List<T>) cb) {
|
|
if (timer?.isActive ?? false) {
|
|
timer!.cancel();
|
|
}
|
|
acc.add(input);
|
|
timer = Timer(Duration(milliseconds: _debounceTime), () async {
|
|
await cb(acc.cast<T>());
|
|
acc.clear();
|
|
});
|
|
}
|