Created
March 28, 2016 11:04
-
-
Save NelsonBrandao/5bc4771d16769ba22482 to your computer and use it in GitHub Desktop.
Promise Collections
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 q = require('q'); | |
| // Parallel | |
| q.all(array.map(function (elem) { | |
| return processElem(elem); | |
| })); | |
| // Or simply | |
| q.all(array.map(processElem)); |
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 q = require('q'); | |
| // If the current element depends on the ones below | |
| array.reduce(function (promise, elem) { | |
| return promise.then(function (result) { | |
| return processElem(elem, result); | |
| }); | |
| }, q()); | |
| // If not | |
| array.reduce(function (promise, elem) { | |
| return promise.then(function () { | |
| return processElem(elem); | |
| }); | |
| }, q()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment