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

Timers, Callbacks and the Event Loop (Summary)

You’ve finished Timers, Callbacks and the Event Loop.

In This Course, You Learned 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

One Picture Behind Every Wait

Your script runs on the call stack, one thing at a time. Kofi’s reminder waits in the waiting area. When it’s due, it joins the task queue. The event loop moves it onto the stack only once the stack is empty.

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 Timers, Callbacks and the Event Loop. In this course, you learned how to: Wait for slow work with timers, without freezing your program. Predict when each callback runs, using the event loop.

00:14 Handle a result or an error with an error-first callback. Notify several listeners with one event. And run the laundry room at 14 Ferris Road.

00:26 Your script runs on the call stack, one thing at a time. Kofi’s reminder waits in the waiting area. When it’s due, it joins the task queue. The event loop moves it onto the stack only once the stack is empty.

00:42 That’s why Kofi’s reminder ran late while Dev sorted the lost socks, until you split the job into chunks.

00:51 With washer 1’s event, only its timer waits. Calling emit() runs every listener right away, on the same stack.

01:01 A timer’s delay is a minimum, not an exact time. A timer’s callback only runs once the call stack is empty. Long synchronous work delays every timer, so split it into chunks.

01:13 In an error-first callback, check for the error first. And emit() calls its listeners right away, in the order you added them.

01:23 One question is still open. Callbacks nest deeper with every step. And the code you hand them to decides when they run, how often, and whether at all. Those problems are why promises exist.

01:37 They’re the next part of the path. Until then, revisit the call stack in Scope, Closures and the Call Stack, and the event loop in the RealJS glossary.

01:49 Thanks for watching.

Become a Member to join the conversation.