Loading video player…

Timers, Callbacks and the Event Loop (Overview)

Welcome to Timers, Callbacks and the Event Loop! So far, your programs have run from top to bottom. Real programs wait: for a timer, for a file, or for a server to reply. This course is about code that waits without freezing. It’s the first course in the Async JavaScript and Web APIs learning path, and you don’t need the other courses in the path to follow it.

The Laundry Room at 14 Ferris Road

Throughout the course, you’ll write a program for the laundry room of a shared house at 14 Ferris Road. Ines, Kofi, Wren, and Dev share its three machines: washer 1, washer 2, and the dryer. Here’s what the finished program prints when you run it:

Language: Text
$ node laundry_room.mjs
Laundry room alert for Kofi: washer 2's door is open
Ines, collect your laundry from washer 1
Ines, your laundry is still in washer 1 (nag 1)
Ines, your laundry is still in washer 1 (nag 2)
Ines emptied washer 1
Dev, collect your laundry from the dryer
Dev, your laundry is still in the dryer (nag 1)
Dev emptied the dryer

Your program tells each housemate when a door’s open or their load is done, and nags them until they collect it. Later in the course, sorting Dev’s lost socks makes every reminder late, and you’ll find out why.

What You’ll Learn

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

  • Wait for slow work with timers, without freezing your program
  • Predict when each callback runs, using the event loop
  • Handle a result or an error with an error-first callback
  • Notify several listeners with one event
  • Run the laundry room at 14 Ferris Road

Before You Start

You need to know about passing functions around, closures and the call stack, modules, errors, and classes. If you’d like a refresher, then these RealJS courses cover them:

For tools, you need a recent 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 four sections ends with a coding exercise in your browser. A three-exercise project brings it together, then an AI mentor session, where you explain your laundry room’s code in your own words and make a change you haven’t seen, followed by a quiz and a summary. There’s a code download, and slides too.

It all starts with one question: How do you wait for the washer without standing over it? The next lesson, Wait Without Blocking, answers it.

Download

Course Slides (.pdf)

2.4 MB
Download

Sample Code (.zip)

17.0 KB

00:00 Welcome to Timers, Callbacks and the Event Loop. So far, your programs have run from top to bottom. Real programs wait for a timer, a file, or a server’s reply.

00:12 This course is about code that waits without freezing.

00:17 Here’s the program you’ll write for the laundry room of a shared house, at 14 Ferris Road. Ines, Kofi, Wren and Dev share its three machines. Your program tells each housemate when a door’s open or their load is done, and nags them until they collect it.

00:34 Later in the course, sorting Dev’s lost socks makes every reminder late.

00:40 In this course, you’ll learn how to: Wait for slow work with timers, without freezing your program. Predict when each callback runs, using the event loop. Handle a result or an error with an error-first callback.

00:55 Notify several listeners with one event. And run the laundry room at 14 Ferris Road.

01:04 It’s the first Async JavaScript and Web APIs course, and you don’t need the others. You need to know about passing functions around, closures and the call stack, modules, errors and classes.

01:16 You’ll need Node, a terminal and any editor. The examples use Node 26.

01:23 The course mixes text lessons and videos, and you run their code in your terminal. Each section ends with a coding exercise in your browser. A three-exercise project brings it together, then an AI mentor session, a quiz and a summary.

01:38 First up: how do you wait for the washer without standing over it? The next lesson, Wait Without Blocking, answers it.

Become a Member to join the conversation.