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 crysmags committed Feb 27, 2024
1 parent 7586941 commit 65fd4e7
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 65fd4e7

Please sign in to comment.