Skip to content

Instantly share code, notes, and snippets.

@Mathspy
Created December 24, 2019 23:20
Show Gist options
  • Save Mathspy/644efccad9d10881912c35d9c3e3a38a to your computer and use it in GitHub Desktop.
Save Mathspy/644efccad9d10881912c35d9c3e3a38a to your computer and use it in GitHub Desktop.
A utility for debugging JS timeouts
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