DEV Community

Discussion on: Promise Chains are Kinda Awesome

Collapse
kosich profile image
Kostia Palchyk

Something is missing here:

    .then(users =>
    .then(map(getEmail))

Nice article! I'm a drBoolean fan too :)

Imho, it'd be nice to see how to parallelize those invitations and grocery shopping requests
(they are independent, right?)

Collapse
bennypowers profile image
Benny Powers 🇮🇱🇨🇦 Author • Edited on

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".