Created
March 25, 2015 12:46
-
-
Save eduardonunesp/95c226ec26a9f97f3613 to your computer and use it in GitHub Desktop.
Async execute forEach with Q Promise
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
var Q = require('q'); | |
var f = function(a) { | |
var defer = Q.defer(); | |
setTimeout(function() { | |
console.log(a); | |
defer.resolve(a); | |
}, a); | |
return defer.promise; | |
}; | |
console.log("Start ..."); | |
Q.all([3000,2000,1000].map(f)).then(function(result) {console.log(result)}); | |
console.log("Lets GO !"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment