hotfix timer lagging

This commit is contained in:
RemiSaurel
2022-08-24 09:04:28 +02:00
parent 1e16a20543
commit f6f958566e
+12 -4
View File
@@ -144,7 +144,13 @@ export default {
this.changeDots(); this.changeDots();
} }
} else { } else {
this.timeout = setTimeout(() => { const interval = 1000; // ms
let expected = Date.now() + interval;
let stepFunc = () => {
let dt = Date.now() - expected;
if (dt > interval) {
// handle error?
}
this.minutes = parseInt(this.minutes); this.minutes = parseInt(this.minutes);
this.seconds = parseInt(this.seconds); this.seconds = parseInt(this.seconds);
if (this.seconds === 0) { if (this.seconds === 0) {
@@ -155,9 +161,11 @@ export default {
} else { } else {
this.seconds -= 1; this.seconds -= 1;
} }
this.prettyTime() this.prettyTime();
this.countDownTimer() expected += interval;
}, 1000) this.timeout = setTimeout(stepFunc, Math.max(0, interval - dt));
}
this.timeout = setTimeout(stepFunc, interval)
} }
}, },
changeDots() { changeDots() {