1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-26 10:50:29 +02:00
immich/mobile/lib/utils/debounce.dart

27 lines
506 B
Dart
Raw Normal View History

import 'dart:async';
import 'package:flutter/material.dart';
class Debounce {
Debounce(Duration interval) : _interval = interval.inMilliseconds;
final int _interval;
Timer? _timer;
VoidCallback? action;
void call(VoidCallback? action) {
this.action = action;
_timer?.cancel();
_timer = Timer(Duration(milliseconds: _interval), _callAndRest);
}
void _callAndRest() {
action?.call();
_timer = null;
}
void dispose() {
_timer?.cancel();
_timer = null;
}
}