Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Promises and async/await (Summary)

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.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 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.

00:14 Write async functions that await each step and catch failures. Predict the order of awaited code, promise callbacks and timers. And plan the Adeyemi family’s day at the museum.

00:27 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.

00:41 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.

00:56 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 loop empties that queue before it moves the next task onto the stack.

01:09 That’s why Grandma Bisi’s tea-break timer, set first, ran last.

01:16 Return each step in a chain, and let one catch handle any failure. When you wrap a callback, settle the promise once on every path. An await pauses the function, not the program.

01:28 Wrap your awaits in try and catch to handle a rejection. And every queued microtask runs before the next task.

01:37 Your last step asked the real museum for one artwork, and only handled a good answer. Status codes and failed requests come later.

01:47 Revisit promises and microtasks in the RealJS glossary.

01:53 Thanks for watching.

Become a Member to join the conversation.