How can I combine sequential and concurrent work in one async function?
Quick answer
Await each prerequisite before starting work that depends on it. Once you have the shared input, start independent operations together with Promise.all(), then await that group before the final step that needs their results. Put a try/catch around the boundary where you want to handle failures. A failure does not by itself cancel sibling work, so use cancellation only when the operations support it.
The question, the details, the next step.
A practical checklist
List each operation and the inputs it needs.
Await prerequisites before starting work that depends on their results.
Put only mutually independent tasks in the
Promise.all()group.Await the group before running a step that needs its results.
Choose where failures are handled; do not assume a failure cancels sibling work.
A few more useful answers
Should I use `Promise.all()` for tasks that can partially succeed?
Use it when the workflow should treat the group as a unit and proceed only after the group completes successfully. If partial results are acceptable, choose and implement a deliberate result-handling strategy; the cited guidance does not prescribe one.
Can I put the final dependent step in the same `Promise.all()` group?
Not if it needs results from the other tasks in that group. Await those results first, then call and await the dependent step.
Does adding an abort signal automatically stop every task in the group?
No. Cancellation is relevant only for operations that accept and honor the signal, and failure alone does not cancel sibling work [S2].
Sources
References used for this guide.
- [S1] Optimize performance and scaling for Node.js Azure Functions learn.microsoft.com · Checked
- [S2] Azure Abort Controller for JavaScript, version 2.2.0 learn.microsoft.com · Checked
