Loading video player…

Concurrency, Failures and Cancellation in Async Code (Overview)

Welcome to Concurrency, Failures and Cancellation in Async Code! Most async examples stop once the code works. This course is about what happens when work fails, runs slow, or starts twice.

The Lindqvists’ Morning

Throughout the course, you’ll build a morning routine for the Lindqvists’ smart home. Its devices are stand-ins: timers with fixed delays and deliberate failures, so you need no hardware.

Erik and Saga want one tap on a “Good morning” button to start the lights, the kettle, the blinds, and the heating. Your routine starts all four devices together. When the blinds go offline, it reports which devices worked. Here’s what that report looks like:

Language: Text
$ node report.mjs
[
  { device: 'turnOnLights', status: 'Lights on' },
  { device: 'boilKettle', status: 'Kettle boiled' },
  { device: 'openBlinds', reason: 'Blinds offline' },
  { device: 'warmUpHeating', status: 'Heating on' }
]

Later, the slow kettle gets a five-second deadline, and Snooze stops whatever hasn’t finished. When Erik and Saga both tap within a second, the kettle boils only once.

What You’ll Learn

By the end of this course, you’ll know how to:

  • Start async work together, and report which jobs worked
  • Run async work one at a time or all together, on purpose
  • Handle failures so none goes unheard
  • Give up on slow work with timeouts and cancellation
  • Find and fix race conditions
  • Build the Lindqvists’ morning routine

Before You Start

This is the third course in the Async JavaScript and Web APIs learning path, and you can start here. You need promises, async functions with await, and try and catch. You also need to predict the order of timers, promise callbacks, and awaited code on the event loop.

If you’d like a refresher, then these RealJS courses cover them:

For tools, you need a current version of Node.js, a terminal, and any editor. The examples use Node.js 26:

Language: Shell
$ node --version
v26.13.1

How the Course Works

The course mixes text lessons and videos, and you run their code in your terminal. Each of the first five sections ends with a coding exercise in your browser. A three-exercise project, an AI mentor session, a quiz, and a summary close the course. You can download the code and slides.

The next lesson is Start Every Device at Once. It asks why starting four devices one after another takes so long.

Download

Course Slides (.pdf)

583.2 KB
Download

Sample Code (.zip)

26.7 KB

00:00 Welcome to Concurrency, Failures and Cancellation in Async Code. Most async examples stop once the code works. This course is about what happens when work fails, runs slow or starts twice.

00:16 Here’s a first taste of the morning routine you’ll build for the Lindqvists’ smart home. Its devices are stand-ins: timers, no hardware.

00:25 Erik and Saga want one “Good morning” tap to start the lights, kettle, blinds and heating. Your routine starts all four together. When the blinds go offline, it reports which devices worked.

00:38 Later, the slow kettle gets a five-second deadline, and Snooze stops whatever hasn’t finished. When both tap within a second, the kettle boils only once.

00:50 In this course, you’ll learn how to: Start async work together, and report which jobs worked. Run async work one at a time or all together, on purpose. Handle failures so none goes unheard.

01:04 Give up on slow work with timeouts and cancellation. Find and fix race conditions. And build the Lindqvists’ morning routine.

01:15 This is the third course in the Async JavaScript and Web APIs path, and you can start here. You need promises, async functions with await, and try and catch.

01:26 You also need to predict the order of timers, promise callbacks and awaited code. You’ll need a terminal, a current Node and any editor.

01:37 The course mixes text lessons and videos. The first five sections each end with a coding exercise in your browser. A three-exercise project, an AI mentor session, a quiz and a summary close the course.

01:50 You can download the code and slides.

01:54 The next lesson is Start Every Device at Once. It asks why starting four devices one after another takes so long.

Become a Member to join the conversation.