Check out a free preview of the full Rethinking Asynchronous JavaScript course

The "Exercise 3" Lesson is part of the full, Rethinking Asynchronous JavaScript course featured in this preview video. Here's what you'd learn in this lesson:

In this exercise, you will use promises to implement the flow-control code for retrieving files.


Transcript from the "Exercise 3" Lesson

>> [MUSIC]

>> Kyle Simpson: So let's practice with promises in a chain. We're gonna go back to the same exercise that we did before. I want you to open up exercise three, and I want to give you the hint that, kind of like what we did in exercise two where getFile produced something, now getFile is going to need to produce a promise.

So we're still gonna call getFile three times. One for file one one for file two one for file three. We're gonna get three promises back, that's the easy part. I'll give you that for free. But now your task is using what I just taught you about how promises chained together.

How are you going to sequence the responses to those promises? In thumps the way we sequenced them was to nest them together, but how do we sequence promises together? I just taught you to, go back and look at those slides and try exercise three. Just so we make sure we're on the same page, let me open that up just so you can see what we're talking about.

Exercise three, this getFile right here on line 22, that's where you need to produce a promise for what's happening. And then we're gonna still call the getFile function three times, and then we're gonna sequence those promises together. So let me give you five or six minutes to try your hand at that.

Go back and look at the last five or six slides that I just showed you. They're gonna tell you exactly how to accomplish that, all of those steps. And see what you can come up with and then we'll talk about that in a few minutes.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now