oto/lib/cli/commands/scheduler/scheduler_interval.dart
2024-12-26 10:32:40 +09:00

32 lines
No EOL
617 B
Dart

import 'package:oto_cli/oto/data/command_data.dart';
class SchedulerInterval {
int interval;
bool activate = true;
bool progress = false;
DataBuild build;
Future Function(DataBuild build) executeFunc;
SchedulerInterval(this.interval, this.build, this.executeFunc) {
startInterval();
}
void startInterval() async {
while(activate) {
await Future.delayed(Duration(milliseconds: interval));
if(!progress) {
execute();
}
}
}
void execute() async {
if(activate) {
progress = true;
await executeFunc(build);
progress = false;
}
}
}