How can I do this in promises?
Assuming processItem
does now not take a callback but returns a promise you would write
all(items.map(processItem)).then(doSomething);
Where all
is your library's all
function that takes an array of promises, like Q.all
. If you don't have one, this simple-minded implementation will do:
function all(promises) {
return promises.reduce(function(m, p) {
return m.then(function(res) {
return r.then(function(r) { return res.concat([r]); });
});
}, fulfill([]));
}
Is there an official place for promises user docs (not the promises spec, workflows and how you'd do them in promises) like there is async?
Nope. Every Promise library does have its own docs, and there are many tutorials on the web. "Official" are only the specs, which I think are short and understandable enough for the user to read though.