Coding is as much a matter of personal growth as it is of logic and control-flow. I keep patience, curiosity, & exuberance in the same toolbox as vim and git.
*Opinions posted are my own*
Good catch. We'll need to wrap that param in a Promise.resolve() to keep it in context. I'll update the snippet presently.
With regard to the totally contrived example, I wholeheartedly agree that this shouldn't be the final code. For one thing, if you're inviting your friends to a dinner party by pinging a REST API via node script, I have some serious questions for you about your priorities. Furthermore, as you correctly pointed out, we could parallelize those calls for performance.
All that being said, this was the best my limited imagination could come up with on short notice. The example is meant to demonstrate OK-ish use of promises and closures, though, rather than document the absolutely most performant code. So let's imagine we have good reason to wait on the invitations. I dunno, maybe there's a restaurant-printshop syndicate in town that only allows enough food to be produced to cover the invitations sent out by the printers.
So you could title this post "asynchronous JavaScript for people who live in improbable towns".
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.
Good catch. We'll need to wrap that param in a
Promise.resolve()
to keep it in context. I'll update the snippet presently.With regard to the totally contrived example, I wholeheartedly agree that this shouldn't be the final code. For one thing, if you're inviting your friends to a dinner party by pinging a REST API via node script, I have some serious questions for you about your priorities. Furthermore, as you correctly pointed out, we could parallelize those calls for performance.
All that being said, this was the best my limited imagination could come up with on short notice. The example is meant to demonstrate OK-ish use of promises and closures, though, rather than document the absolutely most performant code. So let's imagine we have good reason to wait on the invitations. I dunno, maybe there's a restaurant-printshop syndicate in town that only allows enough food to be produced to cover the invitations sent out by the printers.
So you could title this post "asynchronous JavaScript for people who live in improbable towns".