release_schedule/lib/model/delayed_function_caller.dart

22 lines
493 B
Dart
Raw Normal View History

import 'dart:async';
class DelayedFunctionCaller {
2024-01-08 11:56:35 +01:00
final void Function() function;
final Duration duration;
Timer? _timer;
DelayedFunctionCaller(this.function, this.duration);
get scheduled => _timer != null && _timer!.isActive;
void call() {
// If a timer is already active, return.
if (_timer != null && _timer!.isActive) {
return;
}
// Create a timer that calls the function after the specified duration.
2024-01-08 11:56:35 +01:00
_timer = Timer(duration, function);
}
}