Be able to yield an iterable for parallel execution
My usecase with collections from https://github.com/facebook/immutable-js:
co.wrap(function*(list) {
// list is Immutable.Map
const results = yield list.map(function(id) {
return new Promise(function(resolve, reject) {
// ...
});
}
// ...
});
You can use Promise.all: yield Promise.all(iterable).
That's also closer to what you'd do with async functions, which seems like the ultimate endgame.
Thanks. I hadn't thought of Promise.all. I've been reducing iterables to an array.
:+1: for Promise.all - this issue can probably be closed. Since es7 async functions exist now, I wouldn't recommend adding many features that diverge from that line.
Are you saying that Promise.all is better than yield <array of promises> (as map returns array)?
And also in yield <array of promises>, promises don't run in parallel?
Thanks
It seems like co's yield <array of promises> diverges in behavior from await <array of promises>
// co:
var result = yield [Promise.resolve(1)];
result // => [1]
// async/await:
var result = await [Promise.resolve(1)];
result // => [Promise.resolve(1)]
wrapping either with Promise.all would have the same effect