From the course: Advanced Node.js
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Sequential execution with async/await - Node.js Tutorial
From the course: Advanced Node.js
Sequential execution with async/await
- [Instructor] Promises give us a nice way to organize what happens by chaining together .then handlers. We use this technique to compose promise chains that can execute sequentially. But what if you don't want to compose functions in a chain? What happens when you just want to write code? All we really need to do is wait for the result of one promise to complete before running some more code. Do we always have to encapsulate code bits in tiny functions? The answer is no. JavaScript provides us a way to work with promises using code that appears synchronous, but is in fact asynchronous. The solution is async functions. Inside of an async function, you can await for a promise to complete. Let's look at how we can modify the current sequentially executed promise chain using async and await. So the doStuffSequentially function, to get started I'm just gonna go ahead and delete these last lines of code, the last .thens that we added to the doStuffSequentially function. And what I'm gonna…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
Callback pattern8m
-
(Locked)
Resolving promises5m 40s
-
(Locked)
Rejecting promises2m 58s
-
(Locked)
The promisify function5m 18s
-
(Locked)
Sequential execution7m 6s
-
(Locked)
Sequential execution with async/await7m
-
(Locked)
Parallel execution4m 6s
-
(Locked)
Concurrent tasks6m 3s
-
(Locked)
Logging concurrent tasks3m 3s
-
-
-
-