Skip to content

Instantly share code, notes, and snippets.

@SeeThruHead
Last active August 29, 2015 14:24
Show Gist options
  • Save SeeThruHead/10050ff9f458cf478d04 to your computer and use it in GitHub Desktop.
Save SeeThruHead/10050ff9f458cf478d04 to your computer and use it in GitHub Desktop.
function fakePromise(id) {
var deferred = $.Deferred();
setTimeout(function() {
console.log(id + ' is done');
deferred.resolve(id);
}, Math.random() * (1000 - 500) + 500);
return deferred.promise();
}
var ids = [1, 2, 3, 5, 6];
var promises = ids.map(function(id) {
return fakePromise(id);
});
$.when.apply(null, promises).done(function() {
console.log('All done');
console.log(Array.prototype.slice.call(arguments));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment