Skip to content

Instantly share code, notes, and snippets.

@sajadmsNew
Forked from kdziamura/setTimeout.js
Created September 9, 2022 13:15
Show Gist options
  • Save sajadmsNew/0919cc5bb142abf4cb7ef162feb3f367 to your computer and use it in GitHub Desktop.
Save sajadmsNew/0919cc5bb142abf4cb7ef162feb3f367 to your computer and use it in GitHub Desktop.
setTimeout debug
((global, _log = console.log.bind(console)) => {
function log(id, methodName, desc) {
_log(`TIMER #${id}: ${methodName} - ${desc}`);
}
global.setTimeout = (setTimeout => (callback, timeout, ...params) => {
const id = setTimeout((...params) => {
log(id, 'setTimeout', 'create call stack');
callback(...params);
log(id, 'setTimeout', 'end of call stack');
}, timeout, ...params);
log(id, 'setTimeout', `schedule call of ${callback.name || '<anonymous>'}`);
return id;
})(global.setTimeout);
global.clearTimeout = (clearTimeout => (id) => {
log(id, 'clearTimeout', 'remove call from queue');
return clearTimeout(id);
})(global.clearTimeout);
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment