Skip to content

Commit

Permalink
fix: use normal timers for delays < 1s (nodejs#1961)
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag authored and metcoder95 committed Jul 21, 2023
1 parent 69c1e8f commit 8142609
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,15 @@ class Timeout {

module.exports = {
setTimeout (callback, delay, opaque) {
return new Timeout(callback, delay, opaque)
return delay < 1e3
? setTimeout(callback, delay, opaque)
: new Timeout(callback, delay, opaque)
},
clearTimeout (timeout) {
if (timeout && timeout.clear) {
if (timeout instanceof Timeout) {
timeout.clear()
} else {
clearTimeout(timeout)
}
}
}

0 comments on commit 8142609

Please sign in to comment.