Skip to content

Instantly share code, notes, and snippets.

@humanchimp
Created May 12, 2016 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save humanchimp/ef9621d8589b68d3498a2d30bd71d922 to your computer and use it in GitHub Desktop.
Save humanchimp/ef9621d8589b68d3498a2d30bd71d922 to your computer and use it in GitHub Desktop.
let pendingRequests = 0;
$(document)
.ajaxStart(() => { pendingRequests += 1; })
.ajaxStop(() => { pendingRequests -= 1; });
function andThen(callback) {
wait().then(callback);
}
function wait() {
return new RSVP.Promise(resolve => {
const watcher = setInterval(() => {
if (pendingRequests.length) { return; }
clearInterval(watcher);
resolve();
}, 30);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment