watch method
void
watch({})
Starts the one-second tick (sleep detection), the heartbeat every heartbeatEvery, and the ceiling timer.
Implementation
void watch({
required Duration ceiling,
required void Function() onCeiling,
Duration heartbeatEvery = const Duration(seconds: 10),
}) {
_heartbeat = Timer.periodic(const Duration(seconds: 1), (_) {
_noteSleep();
if (clock.elapsedMilliseconds - _lastSentAtMs >= heartbeatEvery.inMilliseconds - 500) _beat();
});
void arm(Duration wait) {
_ceilingTimer = Timer(wait, () {
final left = ceiling - clock.elapsed;
if (left > const Duration(milliseconds: 250)) return arm(left);
onCeiling();
});
}
arm(ceiling);
}