Skip to content

Instantly share code, notes, and snippets.

@pieterbeulque
Last active October 6, 2015 14:56
Show Gist options
  • Save pieterbeulque/ac32049370f174b92cab to your computer and use it in GitHub Desktop.
Save pieterbeulque/ac32049370f174b92cab to your computer and use it in GitHub Desktop.
var ids = [1, 2, 3, 4],
details = [],
fetch = function (id) {
var dfd = new $.Deferred();
new Request({ id: id }, function (res) {
dfd.resolve(res);
});
return dfd.promise();
};
for (var i = 0; i < ids.length; i++) {
details.push(fetch(ids[i]));
}
$.when.apply($, details).then(function () {
for (var i = 0; i < arguments.length; i++) {
var detail = arguments[i];
console.log(detail);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment