start method
Timer
start({
- Duration interval = const Duration(seconds: 1),
- void onSync(
- ReplicationSync sync
- void onError(
- Object error,
- StackTrace stack
Syncs every interval until stop. Errors go to onError and the
next tick tries again (frames not shipped stay in the log).
Implementation
Timer start({
Duration interval = const Duration(seconds: 1),
void Function(ReplicationSync sync)? onSync,
void Function(Object error, StackTrace stack)? onError,
}) {
var running = false;
return Timer.periodic(interval, (_) async {
if (running) {
return;
}
running = true;
try {
final result = await sync();
onSync?.call(result);
} on Object catch (error, stack) {
onError?.call(error, stack);
} finally {
running = false;
}
});
}