Multiple Sequential Awaits
What you'll learn: How multiple await statements in a row create a step-by-step sequence where each operation waits for the previous one to complete.
When you write multiple await statements one after another in an async function, JavaScript pauses at each one until that promise settles, then moves to the next line. This creates a sequential execution flow — just like synchronous code, but for asynchronous operations.
How Sequential Awaits Work
Each await acts like a checkpoint. JavaScript won't proceed to the next line until the current awaited promise resolves:
async function fetchUserData() {
const user = await getUser(123); // Waits here first
const posts = await getUserPosts(user.id); // Then waits here
const comments = await getPostComments(posts[0].id); // Finally waits here
return { user, posts, comments };
}
In this example:
getUser()executes and we wait for it- Only when
useris available,getUserPosts()runs - Only when
postsis available,getPostComments()runs
The Sequential Nature
Think of it like a relay race where each runner waits for the baton. The second runner can't start until the first finishes, and the third can't start until the second finishes.
This is different from running promises concurrently (like with Promise.all). Sequential awaits mean the total time is the sum of all operations:
// If each takes 1 second, this takes ~3 seconds total
async function sequential() {
const a = await delay(1000);
const b = await delay(1000);
const c = await delay(1000);
}
Key Takeaway: Multiple await statements execute one at a time in order, with each line waiting for the previous promise to settle before moving forward — creating predictable, step-by-step async code.