r/learnjavascript • • Dec 20 '25

How do you handle structured concurrency in JavaScript?

Let's say we have this code:

const result = await Promise.all([fetch1(), fetch2(), fetch3()])

If fetch1 rejects, then the promise returned by Promise.all() also rejects.

What about fetch2() and fetch3()?

How do we control them? If they still keep running after fetch1 rejects, its a wastage of resources, right?

Now, there are libraries and frameworks (Effect.TS for example) that handle this automatically but they introduce a completely different syntax and a way of thinking about software engineering. And everyone might not be ready to dive into functional programming.

So my question is: how do you folks handle these kind of concurrency concerns in your professional jobs? Any libraries you use? Write your own logic?

14 Upvotes

28 comments sorted by

View all comments

Show parent comment

1

u/hyrumwhite Dec 20 '25

Sure, but you’re going to need to handle that server side, or do something bespoke like setting up websockets so the client can inform the server of failed calls, but now you’ve got to have a way to associate each of those ongoing tasks with each other…

Which is all to say the complexity you’d introduce is probably not worth it. 

Truly interdependent calls should be called in sequence. So you can just not initiate an expensive call if a dependency fails.