Last active
August 29, 2015 14:24
-
-
Save SeeThruHead/10050ff9f458cf478d04 to your computer and use it in GitHub Desktop.
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
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