Skip to content

Instantly share code, notes, and snippets.

@partap
Last active December 11, 2015 10:48
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 partap/4588807 to your computer and use it in GitHub Desktop.
Save partap/4588807 to your computer and use it in GitHub Desktop.
Sequential loading with jquery Deferred
// a is a jquery collection
// fn is a function that returns a promise
function loadItems(a, fn) {
var d = $.Deferred();
var next = d.promise();
a.each(function () {
var that = this;
next = next.pipe(function () {
return fn(that);
});
});
d.resolve();
return next;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment