Last active
December 11, 2015 10:48
-
-
Save partap/4588807 to your computer and use it in GitHub Desktop.
Sequential loading with jquery Deferred
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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