Skip to content

Commit

Permalink
fixes to new timer system
Browse files Browse the repository at this point in the history
  • Loading branch information
splitice committed Sep 8, 2023
1 parent 74fb772 commit 5b4015b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,15 @@ let nextTickTimer = null
function addTimer(fn, ms){
const now = Date.now()
const timeToRun = now + ms
fn.time = timeToRun

if(nextTimer.time > timeToRun){
nextTimer = fn
nextTimer.time = timeToRun

if(nextTickTimer === null) {
nextTickTimer = setTimeout(executeTimerTick, 25, now + 25)
}
} else {
timers.add(fn)
}

}
Expand All @@ -272,12 +274,16 @@ function adjustTimer(fn, ms){
for(const t in timers){
if(t.time < fn.time) {
nextTimer = t
clearTimeout(nextTickTimer)
timers.add(fn)
return
}
}
}
}else{
if(fn.time < nextTimer.time){
timers.add(nextTimer)
nextTimer = fn
}
}
}

function clearTimer(fn){
Expand Down

0 comments on commit 5b4015b

Please sign in to comment.