In many cases it may be beneficial if the callback waits for a return, before starting the next callback. We can achieve this by switching from setInterval to recursive setTimeout use like this:
function makeRequest() {
$.get('your/url', function(data) {
// Handle your data here
// Schedule the next request when the current one's complete
setTimeout(makeRequest, {{ interval }} * 1000);
});
}
// Make the initial request
makeRequest();
Also, we can leave it to the user to decide how exactly they want their callback to be handled. I think the setTimeout method should be the (new) default, but the setInterval method should still be selectable.
In many cases it may be beneficial if the callback waits for a return, before starting the next callback. We can achieve this by switching from setInterval to recursive setTimeout use like this:
Also, we can leave it to the user to decide how exactly they want their callback to be handled. I think the setTimeout method should be the (new) default, but the setInterval method should still be selectable.