|
|
|
|
|
by graue
4830 days ago
|
|
This code doesn't look right to me: // list :: [Promise a] -> Promise [a]
var list = function(promises) {
var listPromise = new Promise();
for (var k in listPromise) promises[k] = listPromise[k];
Perhaps the assignment is supposed to be the other way around? for (var k in promises) listPromise[k] = promises[k];
|
|
Promise libraries, like RSVP.js [1] he referred to, typically implement a way to construct a promise with a depends-on-many relationship, as a function possibly called `all([p1, p2, ...])` (with the same type signature as for `list`), `and(p1, p2, ...)` or something similar.
IMO, defining the `list` function that way would've been clearer to the reader and more FP'ish, treating the `promises` argument in as a value and not a mutable object.
[1]: https://github.com/tildeio/rsvp.js/blob/master/lib/rsvp/all....