Skip to content

Instantly share code, notes, and snippets.

@kdziamura
Created May 5, 2016 11:22
Show Gist options
  • Save kdziamura/9aa265333bb678a164a4c53758a900ca to your computer and use it in GitHub Desktop.
Save kdziamura/9aa265333bb678a164a4c53758a900ca 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