Skip to content

Commit

Permalink
fix: use Number for clock.dt
Browse files Browse the repository at this point in the history
  • Loading branch information
3mcd committed Jun 14, 2020
1 parent 057e8b5 commit 55ce8d2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/hrtime-loop/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ enum LoopState {
Running,
}

export const NS_PER_MS = BigInt(1e6)
export const NS_PER_MS = 1e6
export const NS_PER_MS_BIGINT = BigInt(1e6)

/**
* This loop uses the fairly performant setImmediate scheduler in conjunction
Expand Down Expand Up @@ -53,8 +54,8 @@ export const createHrtimeLoop = (
remaining -= diff

if (remaining <= 0) {
clock.dt = Number((remaining + nsPerTick) / NS_PER_MS)
clock.now = time / NS_PER_MS
clock.dt = Number(remaining + nsPerTick) / NS_PER_MS
clock.now = time / NS_PER_MS_BIGINT
clock.tick = clock.tick + 1

callback(clock)
Expand All @@ -63,7 +64,7 @@ export const createHrtimeLoop = (
} else if (remaining < Number(nsPerTick) / 8) {
setImmediate(loop)
} else {
setTimeout(loop, Number(remaining / NS_PER_MS))
setTimeout(loop, Number(remaining) / NS_PER_MS)
}

previous = time
Expand Down

0 comments on commit 55ce8d2

Please sign in to comment.