I'm working with an AWS lambda function that has a sort of 'map/reduce' feel to it. But the 'map' part of it, that is the part that does multiple calls is async.
Using the Node 6 STD lib, is there a dynamic way to get all results returned to a shared spot.
What I've thought about so far:
await asyncis a great abstraction but isn't in node 6 to my knowledge, just node 8.array.reducesays it takes a callback but the structure of an http request seems not to qualify though I certainly may be wrong- I've thought about a really suboptimal solution, where each callback puts into a shared queue or array. And I have a loop after all the requests that checks the length of the array - I don't like this solution though
Could you guys point me in the right direction or show me some code that would do this?
Bluebird is your friend.
To convert callback functions into promises you can use
.promisify()or.fromCallback().To do map/reduce over an array of promises, you can use
.map()and.reduce().