Skip to content

Commit

Permalink
fix: use normal timers for delays < 1s (#1961)
Browse files Browse the repository at this point in the history
Fixes: #1950
  • Loading branch information
ronag authored Feb 22, 2023
1 parent 0beedf9 commit e959307
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 e959307

Please sign in to comment.