Skip to content

Instantly share code, notes, and snippets.

@nadinengland
Created December 17, 2013 14:23
Show Gist options
  • Save nadinengland/8005636 to your computer and use it in GitHub Desktop.
Save nadinengland/8005636 to your computer and use it in GitHub Desktop.
Queuing Deferred Tasks
var Queue = function () {
var previous = new $.Deferred().resolve();
return function (fn, fail) {
return previous = previous.then(fn, fail || fn);
};
};
var queue = Queue();
var values = [...];
values.forEach(function (value) {
queue(function () {
return $.post('/', value);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment