const orderPromises = orders.map(order => api.sendOrder(order)); Promise.all(orderPromisses).then(arrayOfResponses => { // do your stuff })
You have over overengineered this and your solution wasn't really working as it should.
Yes, This is definitely the solution! Node has native support for dealing with multiple async promises.
You could even remove the variable assignment (though JS is going to assign it to a temp anyways);
return Promise.all(orders.map(api.sendOrder)) .then(allOrders => { ... });
Thats if sendOrder does not need its functional context. Semantically the same solution, though.
sendOrder
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You have over overengineered this and your solution wasn't really working as it should.
Yes, This is definitely the solution! Node has native support for dealing with multiple async promises.
You could even remove the variable assignment (though JS is going to assign it to a temp anyways);
Thats if
sendOrder
does not need its functional context. Semantically the same solution, though.