Last active
November 15, 2016 15:46
-
-
Save DaniilBabanin/20c33d50cb981cf3dbb8d743612d25aa to your computer and use it in GitHub Desktop.
Q.all with array map
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
return array.reduce(function(p, item) { | |
return p.then(function(){ return readFile(item); }); | |
},Q()); |
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
Q.all(array.map(function (item) { | |
return doSomething(item); //function that returns promise | |
})) | |
.then(function (resolves) { | |
connection.response.items = resolves; | |
deferred.resolve(); | |
}) | |
.catch(function (err) { | |
deferred.reject(err); | |
}) | |
; |
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
Q.all(array.map(function (item) { | |
return doSomething.bind(this, item); //use bind this to run function in Q.ll insted of the map function | |
})) | |
.then(function (resolves) { | |
connection.response.items = resolves; | |
deferred.resolve(); | |
}) | |
.catch(function (err) { | |
deferred.reject(err); | |
}) | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment