r/learnjavascript • u/HKSundaray • 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?
View all comments
Show parent comment
1
u/HKSundaray Dec 20 '25
thats my point. Why let the server execute the rest of the promises when one fails. We might need them all to resolve and the promises that ran might might cost us (a LLM API call for example). So we would want them to stop continuing. Am I making sense?