Created
January 7, 2016 15:32
-
-
Save jtbonhomme/9a66945f0adfc08d42dd to your computer and use it in GitHub Desktop.
Promises loop
This file contains hidden or 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
var Promise = require('bluebird'); | |
var promises = []; | |
for(var i = 0 ; i<10; i++) { | |
var that = this; | |
promises.push(new Promise(function(fulfill, reject) { | |
setTimeout(function(){ | |
console.log('Fulfill '); | |
fulfill(); | |
}, 1000+Math.random()*10000); | |
})); | |
} | |
Promise.all(promises).then(function(){ | |
console.log('done'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment