You’ve finished Promises and async/await.
In This Course, You Learned How To
- Handle a value that arrives later with a promise
- Chain steps that depend on each other, and wrap a callback in a promise
- Write async functions that await each step and catch failures
- Predict the order of awaited code, promise callbacks and timers
- Plan the Adeyemi family’s day at the museum
A Value That Arrives Later
A promise is pending until it settles, once, as fulfilled or rejected. Then it keeps its value.
In a chain, each step returns a value or a promise for the next step. When Tunde’s pick wasn’t on view, the rejection skipped the handlers after it, down to one catch.
With await, an async function reads top to bottom. At each await, it steps aside, and your program carries on.
Once a promise settles, its handlers and the code after an await line up in a second queue, the microtask queue. When the stack is empty, the event loop empties that queue before it moves the next task onto the stack. That’s why Grandma Bisi’s tea-break timer, set first, ran last.