Starting Promises Before Awaiting
You'll learn how to maximize performance by starting multiple async operations immediately, then awaiting their results only when needed.
The Core Idea
When you write await someAsyncFunction(), the function starts and you immediately pause to wait for it. But here's the key insight: you can call an async function without await first—it returns a promise that begins executing immediately. Store that promise in a variable, do other work (or start other promises), then await the stored promise later.
Think of it like ordering food at multiple restaurant counters. You don't stand at the first counter watching your order get made, then move to the second counter. Instead, you place all your orders first (starting each process), then collect the finished items when they're ready.
How It Works
async function fetchUserData() {
// DON'T do this - fully sequential:
const profile = await getProfile();
const posts = await getPosts();
// DO this - start both immediately:
const profilePromise = getProfile(); // starts now, no await
const postsPromise = getPosts(); // starts now too
const profile = await profilePromise; // pause only when you need the value
const posts = await postsPromise; // likely already resolved!
}
The second approach starts both operations at nearly the same time, while the first waits for getProfile() to completely finish before even starting getPosts().
When to Use This Pattern
Use this when:
- Operations are independent (neither needs the other's result)
- You want
Promise.allperformance but need to handle results separately - You need values at different points in your function
Key Takeaway: Calling an async function without await starts it immediately and returns a promise you can await later—use this to run independent operations in parallel without always reaching for Promise.all.