Skip to content

Commit

Permalink
shared; Timer optimization (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yiin authored Oct 2, 2023
1 parent 1e48df8 commit efc7e3c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions shared/js/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ class Timer {
}

tick() {
if (this.interval === 0 || Date.now() - this.lastTick > this.interval) {
const start = Date.now();
const now = Date.now();
if (this.interval === 0 || now - this.lastTick > this.interval) {
const start = now;
try {
this.callback();
} catch (e) {
Expand Down Expand Up @@ -202,7 +203,7 @@ globalThis.clearTimeout = (timeout) => {
};

function tick() {
for (const [_, timer] of timers) {
for (const timer of timers.values()) {
timer.tick();
}
}
Expand Down

0 comments on commit efc7e3c

Please sign in to comment.