Considering that AJAX callbacks are dependent on the server response(success, failure), you can't define if they are pending to be called, until it's actually time to call them.
But here's an idea how this checking can be achieved for setTimeout
(and maybe setInterval
):
window.timeoutsRegistry = [];
window.oldSetTimeout = window.setTimeout;
window.setTimeout = function(func, delay) {
var tId = window.oldSetTimeout(function() {
try {
func();
}
catch (exception) {
//Do Error Handling
}
}, delay);
var startedAt = (+new Date);
window.timeoutsRegistry[tId] = {
id: tId,
callback: func,
delay: delay,
startedAt: startedAt,
isPending: function () {
var now = (+new Date);
return ((startedAt + delay) > now);
}
};
};
for(var i =0; i < 10; i++) {
setTimeout(function() {
1+1;
}, 200000);
}
console.log(window.timeoutsRegistry);
var pending = window.timeoutsRegistry.filter(function(element) {
return element.isPending();
});
console.log(pending);
Some notes: