Created
December 24, 2019 23:20
-
-
Save Mathspy/644efccad9d10881912c35d9c3e3a38a to your computer and use it in GitHub Desktop.
A utility for debugging JS timeouts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('log-timestamp'); | |
const timers = []; | |
function setTimeout(fn, time) { | |
const ret = global.setTimeout(() => { | |
console.log(`Finished timer ${timers.indexOf(ret)} after ${time}`); | |
fn(); | |
}, time); | |
console.log(`Started timer ${timers.push(ret) - 1} with ${time}`); | |
return ret; | |
} | |
function clearTimeout(id) { | |
console.log(`Clearing timer ${timers.indexOf(id)}`); | |
global.clearTimeout(id); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment