---
title: "Chapter 10. Continuations"
url: "https://www.mikefluff.com/en/read/from-closures-to-autonomous-systems/ch10"
locale: "en"
author: "Mikhail Savchenko (Mike Fluff)"
updated: "2026-11-18T12:24:57.879Z"
book: "https://www.mikefluff.com/en/books/from-closures-to-autonomous-systems"
access: "lead-in"
purchase: "https://www.mikefluff.com/en/books/from-closures-to-autonomous-systems"
alternates:
  - locale: "ru"
    url: "https://www.mikefluff.com/ru/read/from-closures-to-autonomous-systems/ch10"
    markdown: "https://www.mikefluff.com/ru/read/from-closures-to-autonomous-systems/ch10.md"
  - locale: "en"
    url: "https://www.mikefluff.com/en/read/from-closures-to-autonomous-systems/ch10"
    markdown: "https://www.mikefluff.com/en/read/from-closures-to-autonomous-systems/ch10.md"
  - locale: "pt"
    url: "https://www.mikefluff.com/pt/read/from-closures-to-autonomous-systems/ch10"
    markdown: "https://www.mikefluff.com/pt/read/from-closures-to-autonomous-systems/ch10.md"
---

# Chapter 10. Continuations

*[JavaScript: From Closures to Autonomous Systems](https://www.mikefluff.com/en/books/from-closures-to-autonomous-systems)*

I learned to program on Meteor and for quite a long time had no idea that asynchrony in JavaScript could be difficult at all. Code on the server looked the way code looks in a textbook: read from the database, compute, write back, line by line, top to bottom. Why it worked that way I will explain in the next chapter. I learned about the difficulties when I stepped outside Meteor and saw how the very same code is written in plain Node. Before `async/await` arrived, the community called such code callback hell, and the name was deserved.

To understand where that hell came from, you need one concept from programming language theory. A continuation is everything the program will do after the current line. When an ordinary synchronous program says `const user = db.find(id)` followed by ten more lines, those ten lines are the continuation. The programmer does not need to store it; the call stack does that for free: while `db.find` runs, somewhere in memory there is a note saying where to return and with which variables to continue.

Node cancelled this free service. If a database read cannot be waited for, because there is only one thread and it has no right to wait, then the read function must return control immediately and deliver the result later. But then what should happen to those ten lines? Node’s answer was blunt: wrap them in a function and hand it to the read function, which will call it when the data arrives. The programmer started packing up the rest of the program and passing it from hand to hand. In theory this is called continuation-passing style, and before Node it was mostly compilers that wrote this way, transforming programs into this form automatically. In Node, people wrote this way.

---

The rest of this chapter is free on the site once the reader confirms an email address: https://www.mikefluff.com/en/read/from-closures-to-autonomous-systems/ch10
