Wraps window.setTimeout to log a stack trace whenever a delayed callback fires. Useful for debugging timing issues in ESRI/ArcGIS JavaScript API applications.
Note: For debugging and development only — do not use in production.
const originalSetTimeout = window.setTimeout;
window.setTimeout = (cb, delay) => {
// Let's ignore the delay and make the callback fire immediately
if ( String(cb)!='function(){return a.apply(c,arguments||[])}' && delay != 0) {
console.trace('cb: ',cb.arguments, ' creds:', esri.id.credentials,' delay: ', delay);
var monkey = function(){
console.trace('done:',cb, ' creds:', esri.id.credentials, 'after:', delay);
cb.apply (this, cb.arguments);
}
return originalSetTimeout(monkey, delay);
}
return originalSetTimeout(cb, delay);
};