Node.js • Chapter 16 • Beginner Friendly
Timers Scheduling and Cancellation
Learn this chapter by understanding what each Node.js feature does, when to use it, how it can fail, and how to verify the result.
16.1 setTimeout
setTimeout is part of Chapter 16, “Timers Scheduling and Cancellation.” For a beginner, the first goal is to understand the observable behavior before memorizing an API. In this lesson, I/O means input/output work such as files, streams, timers, and events. The practical focus is inputs, observable output, error behavior, and the resource that the operation consumes.
Start from the smallest working behavior and name every input and output. In Chapter 16 (Timers Scheduling and Cancellation), for setTimeout, write down what enters the operation, what Node.js is expected to do, and what the caller can observe afterward. If the result is asynchronous, also state when completion is known and where errors travel.
For setTimeout in Chapter 16, the mechanism to keep in mind is streaming data safely without blocking the main JavaScript thread. A good experiment changes one thing at a time and checks both success and failure. When you finish this topic, you should be able to explain why the code works, not only copy the syntax.
Key terms in plain language
- I/O — input/output work such as files, streams, timers, and events.
- setTimeout — a concrete part of settimeout that the lesson isolates so you can see its effect instead of treating the whole feature as a black box.
10 teaching examples
Example 1: Minimal working case
In Chapter 16 (Timers Scheduling and Cancellation), build the smallest setTimeout example that has one clear input and one visible result. Before running it, write what you expect to happen. Then verify inputs, observable output, error behavior, and the resource that the operation consumes. This establishes a baseline you can reason about.
Example 2: Change one input
For Chapter 16 (Timers Scheduling and Cancellation), keep the same program but change exactly one input related to setTimeout. Compare the two outputs and explain why the change happened. This teaches cause and effect instead of memorizing syntax.
Example 3: Compare two approaches
Within Timers Scheduling and Cancellation, solve one tiny task twice: first with the most direct approach to setTimeout, then with a reasonable alternative. Compare readability, error behavior, and resource use. Choose the version whose tradeoff matches the task.
Example 4: Failure you can recognize
For Timers Scheduling and Cancellation, create a safe failure involving setTimeout, such as invalid data, a missing resource, a closed connection, or a rejected promise. Observe the error type and decide where the program should handle it rather than hiding it.
Example 5: Real service scenario
Imagine a small tutoring-service backend applying setTimeout during Chapter 16 (Timers Scheduling and Cancellation). State what arrives from the caller, what the Node.js process must do, what it returns, and what must be logged if the operation fails.
Example 6: Security or trust check
In the Timers Scheduling and Cancellation context, treat one value used by setTimeout as untrusted. Identify what must be validated, encoded, bounded, or refused before the value reaches a sensitive operation. Explain the consequence of trusting it blindly.
Example 7: Concurrency check
For Chapter 16, run or reason about two setTimeout operations close together. Ask whether ordering matters, whether shared state can conflict, and whether work should be awaited, queued, streamed, or moved to another worker.
Example 8: Performance check
While studying Timers Scheduling and Cancellation, measure the resource most affected by setTimeout: elapsed time, bytes, memory, open connections, event-loop delay, or database round trips. Optimize only after the measurement identifies a meaningful cost.
Example 9: Refactoring example
In a Timers Scheduling and Cancellation exercise, take code that mixes setTimeout with unrelated business logic and split it into a small function with an explicit input and return value. The caller should not need to know low-level details unless they are part of the contract.
Example 10: Production reasoning
Assume the setTimeout code from Chapter 16 runs thousands of times. Decide what needs a timeout, limit, retry rule, cleanup step, metric, or graceful-shutdown hook. The goal is predictable behavior under repetition, load, and partial failure.
Node.js coding example
// Topic: setTimeout
import { Readable } from 'node:stream';
import { pipeline } from 'node:stream/promises';
import { createWriteStream } from 'node:fs';
const source = Readable.from(['chapter 16\n', "setTimeout\\n"]);
await pipeline(source, createWriteStream('node-topic-16-1.txt'));
console.log('saved');Step-by-step code explanation
- Create a readable stream from two small chunks.
- Create a writable file stream.
- Use pipeline so stream errors are propagated and cleanup is coordinated.
- Wait for completion before printing the confirmation.
Expected output: saved, and a small text file is created.
Practice exercise
Build a small Chapter 16 example for setTimeout. Write the expected result before running it. Add one failure case, then change exactly one condition and explain why the behavior changed. For production reasoning, identify one limit, timeout, cleanup step, or validation rule that would make the code safer.
16.2 setInterval
setInterval is part of Chapter 16, “Timers Scheduling and Cancellation.” For a beginner, the first goal is to understand the observable behavior before memorizing an API. In this lesson, I/O means input/output work such as files, streams, timers, and events. The practical focus is inputs, observable output, error behavior, and the resource that the operation consumes.
Compare the correct approach with a common alternative so the tradeoff is visible. In Chapter 16 (Timers Scheduling and Cancellation), the useful comparison for setInterval is not “short code versus long code”; it is predictable behavior versus hidden assumptions. Check platform differences, lifetime of resources, and whether the caller must wait for completion.
For setInterval in Chapter 16, the mechanism to keep in mind is streaming data safely without blocking the main JavaScript thread. A good experiment changes one thing at a time and checks both success and failure. When you finish this topic, you should be able to explain why the code works, not only copy the syntax.
Key terms in plain language
- I/O — input/output work such as files, streams, timers, and events.
- setInterval — a concrete part of setinterval that the lesson isolates so you can see its effect instead of treating the whole feature as a black box.
10 teaching examples
Example 1: Compare two approaches
Within Timers Scheduling and Cancellation, solve one tiny task twice: first with the most direct approach to setInterval, then with a reasonable alternative. Compare readability, error behavior, and resource use. Choose the version whose tradeoff matches the task.
Example 2: Failure you can recognize
For Timers Scheduling and Cancellation, create a safe failure involving setInterval, such as invalid data, a missing resource, a closed connection, or a rejected promise. Observe the error type and decide where the program should handle it rather than hiding it.
Example 3: Real service scenario
Imagine a small tutoring-service backend applying setInterval during Chapter 16 (Timers Scheduling and Cancellation). State what arrives from the caller, what the Node.js process must do, what it returns, and what must be logged if the operation fails.
Example 4: Security or trust check
In the Timers Scheduling and Cancellation context, treat one value used by setInterval as untrusted. Identify what must be validated, encoded, bounded, or refused before the value reaches a sensitive operation. Explain the consequence of trusting it blindly.
Example 5: Concurrency check
For Chapter 16, run or reason about two setInterval operations close together. Ask whether ordering matters, whether shared state can conflict, and whether work should be awaited, queued, streamed, or moved to another worker.
Example 6: Performance check
While studying Timers Scheduling and Cancellation, measure the resource most affected by setInterval: elapsed time, bytes, memory, open connections, event-loop delay, or database round trips. Optimize only after the measurement identifies a meaningful cost.
Example 7: Refactoring example
In a Timers Scheduling and Cancellation exercise, take code that mixes setInterval with unrelated business logic and split it into a small function with an explicit input and return value. The caller should not need to know low-level details unless they are part of the contract.
Example 8: Production reasoning
Assume the setInterval code from Chapter 16 runs thousands of times. Decide what needs a timeout, limit, retry rule, cleanup step, metric, or graceful-shutdown hook. The goal is predictable behavior under repetition, load, and partial failure.
Example 9: Minimal working case
In Chapter 16 (Timers Scheduling and Cancellation), build the smallest setInterval example that has one clear input and one visible result. Before running it, write what you expect to happen. Then verify inputs, observable output, error behavior, and the resource that the operation consumes. This establishes a baseline you can reason about.
Example 10: Change one input
For Chapter 16 (Timers Scheduling and Cancellation), keep the same program but change exactly one input related to setInterval. Compare the two outputs and explain why the change happened. This teaches cause and effect instead of memorizing syntax.
Node.js coding example
// Topic: setInterval
import { Readable } from 'node:stream';
import { pipeline } from 'node:stream/promises';
import { createWriteStream } from 'node:fs';
const source = Readable.from(['chapter 16\n', "setInterval\\n"]);
await pipeline(source, createWriteStream('node-topic-16-2.txt'));
console.log('saved');Step-by-step code explanation
- Create a readable stream from two small chunks.
- Create a writable file stream.
- Use pipeline so stream errors are propagated and cleanup is coordinated.
- Wait for completion before printing the confirmation.
Expected output: saved, and a small text file is created.
Practice exercise
Build a small Chapter 16 example for setInterval. Write the expected result before running it. Add one failure case, then change exactly one condition and explain why the behavior changed. For production reasoning, identify one limit, timeout, cleanup step, or validation rule that would make the code safer.
16.3 setImmediate
setImmediate is part of Chapter 16, “Timers Scheduling and Cancellation.” For a beginner, the first goal is to understand the observable behavior before memorizing an API. In this lesson, I/O means input/output work such as files, streams, timers, and events. The practical focus is inputs, observable output, error behavior, and the resource that the operation consumes.
Deliberately inspect a failure case because error behavior is part of the API. In Chapter 16 (Timers Scheduling and Cancellation), a robust understanding of setImmediate includes its failure path. Ask what happens with missing data, invalid input, a closed resource, cancellation, or partial completion. Handling those cases deliberately is part of correct Node.js design.
For setImmediate in Chapter 16, the mechanism to keep in mind is streaming data safely without blocking the main JavaScript thread. A good experiment changes one thing at a time and checks both success and failure. When you finish this topic, you should be able to explain why the code works, not only copy the syntax.
Key terms in plain language
- I/O — input/output work such as files, streams, timers, and events.
- setImmediate — a concrete part of setimmediate that the lesson isolates so you can see its effect instead of treating the whole feature as a black box.
10 teaching examples
Example 1: Real service scenario
Imagine a small tutoring-service backend applying setImmediate during Chapter 16 (Timers Scheduling and Cancellation). State what arrives from the caller, what the Node.js process must do, what it returns, and what must be logged if the operation fails.
Example 2: Security or trust check
In the Timers Scheduling and Cancellation context, treat one value used by setImmediate as untrusted. Identify what must be validated, encoded, bounded, or refused before the value reaches a sensitive operation. Explain the consequence of trusting it blindly.
Example 3: Concurrency check
For Chapter 16, run or reason about two setImmediate operations close together. Ask whether ordering matters, whether shared state can conflict, and whether work should be awaited, queued, streamed, or moved to another worker.
Example 4: Performance check
While studying Timers Scheduling and Cancellation, measure the resource most affected by setImmediate: elapsed time, bytes, memory, open connections, event-loop delay, or database round trips. Optimize only after the measurement identifies a meaningful cost.
Example 5: Refactoring example
In a Timers Scheduling and Cancellation exercise, take code that mixes setImmediate with unrelated business logic and split it into a small function with an explicit input and return value. The caller should not need to know low-level details unless they are part of the contract.
Example 6: Production reasoning
Assume the setImmediate code from Chapter 16 runs thousands of times. Decide what needs a timeout, limit, retry rule, cleanup step, metric, or graceful-shutdown hook. The goal is predictable behavior under repetition, load, and partial failure.
Example 7: Minimal working case
In Chapter 16 (Timers Scheduling and Cancellation), build the smallest setImmediate example that has one clear input and one visible result. Before running it, write what you expect to happen. Then verify inputs, observable output, error behavior, and the resource that the operation consumes. This establishes a baseline you can reason about.
Example 8: Change one input
For Chapter 16 (Timers Scheduling and Cancellation), keep the same program but change exactly one input related to setImmediate. Compare the two outputs and explain why the change happened. This teaches cause and effect instead of memorizing syntax.
Example 9: Compare two approaches
Within Timers Scheduling and Cancellation, solve one tiny task twice: first with the most direct approach to setImmediate, then with a reasonable alternative. Compare readability, error behavior, and resource use. Choose the version whose tradeoff matches the task.
Example 10: Failure you can recognize
For Timers Scheduling and Cancellation, create a safe failure involving setImmediate, such as invalid data, a missing resource, a closed connection, or a rejected promise. Observe the error type and decide where the program should handle it rather than hiding it.
Node.js coding example
// Topic: setImmediate
import { Readable } from 'node:stream';
import { pipeline } from 'node:stream/promises';
import { createWriteStream } from 'node:fs';
const source = Readable.from(['chapter 16\n', "setImmediate\\n"]);
await pipeline(source, createWriteStream('node-topic-16-3.txt'));
console.log('saved');Step-by-step code explanation
- Create a readable stream from two small chunks.
- Create a writable file stream.
- Use pipeline so stream errors are propagated and cleanup is coordinated.
- Wait for completion before printing the confirmation.
Expected output: saved, and a small text file is created.
Practice exercise
Build a small Chapter 16 example for setImmediate. Write the expected result before running it. Add one failure case, then change exactly one condition and explain why the behavior changed. For production reasoning, identify one limit, timeout, cleanup step, or validation rule that would make the code safer.
16.4 Promise-Based Timers
Promise-Based Timers is part of Chapter 16, “Timers Scheduling and Cancellation.” For a beginner, the first goal is to understand the observable behavior before memorizing an API. In this lesson, I/O means input/output work such as files, streams, timers, and events. The practical focus is completion order, rejection paths, and concurrency limits.
Connect the idea to a small service or automation task that a learner could actually build. In Chapter 16 (Timers Scheduling and Cancellation), connect Promise-Based Timers to a small backend, automation script, or command-line tool. That makes the API easier to remember because each method call has a reason, a boundary, and an expected result.
For Promise-Based Timers in Chapter 16, the mechanism to keep in mind is streaming data safely without blocking the main JavaScript thread. A good experiment changes one thing at a time and checks both success and failure. When you finish this topic, you should be able to explain why the code works, not only copy the syntax.
Key terms in plain language
- I/O — input/output work such as files, streams, timers, and events.
- Promise-Based — a concrete part of promise-based timers that the lesson isolates so you can see its effect instead of treating the whole feature as a black box.
- Timers — a concrete part of promise-based timers that the lesson isolates so you can see its effect instead of treating the whole feature as a black box.
10 teaching examples
Example 1: Concurrency check
For Chapter 16, run or reason about two Promise-Based Timers operations close together. Ask whether ordering matters, whether shared state can conflict, and whether work should be awaited, queued, streamed, or moved to another worker.
Example 2: Performance check
While studying Timers Scheduling and Cancellation, measure the resource most affected by Promise-Based Timers: elapsed time, bytes, memory, open connections, event-loop delay, or database round trips. Optimize only after the measurement identifies a meaningful cost.
Example 3: Refactoring example
In a Timers Scheduling and Cancellation exercise, take code that mixes Promise-Based Timers with unrelated business logic and split it into a small function with an explicit input and return value. The caller should not need to know low-level details unless they are part of the contract.
Example 4: Production reasoning
Assume the Promise-Based Timers code from Chapter 16 runs thousands of times. Decide what needs a timeout, limit, retry rule, cleanup step, metric, or graceful-shutdown hook. The goal is predictable behavior under repetition, load, and partial failure.
Example 5: Minimal working case
In Chapter 16 (Timers Scheduling and Cancellation), build the smallest Promise-Based Timers example that has one clear input and one visible result. Before running it, write what you expect to happen. Then verify completion order, rejection paths, and concurrency limits. This establishes a baseline you can reason about.
Example 6: Change one input
For Chapter 16 (Timers Scheduling and Cancellation), keep the same program but change exactly one input related to Promise-Based Timers. Compare the two outputs and explain why the change happened. This teaches cause and effect instead of memorizing syntax.
Example 7: Compare two approaches
Within Timers Scheduling and Cancellation, solve one tiny task twice: first with the most direct approach to Promise-Based Timers, then with a reasonable alternative. Compare readability, error behavior, and resource use. Choose the version whose tradeoff matches the task.
Example 8: Failure you can recognize
For Timers Scheduling and Cancellation, create a safe failure involving Promise-Based Timers, such as invalid data, a missing resource, a closed connection, or a rejected promise. Observe the error type and decide where the program should handle it rather than hiding it.
Example 9: Real service scenario
Imagine a small tutoring-service backend applying Promise-Based Timers during Chapter 16 (Timers Scheduling and Cancellation). State what arrives from the caller, what the Node.js process must do, what it returns, and what must be logged if the operation fails.
Example 10: Security or trust check
In the Timers Scheduling and Cancellation context, treat one value used by Promise-Based Timers as untrusted. Identify what must be validated, encoded, bounded, or refused before the value reaches a sensitive operation. Explain the consequence of trusting it blindly.
Node.js coding example
// Topic: Promise-Based Timers
import { Readable } from 'node:stream';
import { pipeline } from 'node:stream/promises';
import { createWriteStream } from 'node:fs';
const source = Readable.from(['chapter 16\n', "Promise-Based Timers\\n"]);
await pipeline(source, createWriteStream('node-topic-16-4.txt'));
console.log('saved');Step-by-step code explanation
- Create a readable stream from two small chunks.
- Create a writable file stream.
- Use pipeline so stream errors are propagated and cleanup is coordinated.
- Wait for completion before printing the confirmation.
Expected output: saved, and a small text file is created.
Practice exercise
Build a small Chapter 16 example for Promise-Based Timers. Write the expected result before running it. Add one failure case, then change exactly one condition and explain why the behavior changed. For production reasoning, identify one limit, timeout, cleanup step, or validation rule that would make the code safer.
16.5 AbortController and Cancelled Work
AbortController and Cancelled Work is part of Chapter 16, “Timers Scheduling and Cancellation.” For a beginner, the first goal is to understand the observable behavior before memorizing an API. In this lesson, I/O means input/output work such as files, streams, timers, and events. The practical focus is inputs, observable output, error behavior, and the resource that the operation consumes.
Finish by asking what changes when the code runs repeatedly, concurrently, or with untrusted input. In Chapter 16 (Timers Scheduling and Cancellation), production code using AbortController and Cancelled Work should be reviewable by another developer. Keep responsibilities small, add limits around untrusted or repeated work, and record enough context to diagnose failures without exposing secrets.
For AbortController and Cancelled Work in Chapter 16, the mechanism to keep in mind is streaming data safely without blocking the main JavaScript thread. A good experiment changes one thing at a time and checks both success and failure. When you finish this topic, you should be able to explain why the code works, not only copy the syntax.
Key terms in plain language
- I/O — input/output work such as files, streams, timers, and events.
- AbortController — a concrete part of abortcontroller and cancelled work that the lesson isolates so you can see its effect instead of treating the whole feature as a black box.
- Cancelled — a concrete part of abortcontroller and cancelled work that the lesson isolates so you can see its effect instead of treating the whole feature as a black box.
- Work — a concrete part of abortcontroller and cancelled work that the lesson isolates so you can see its effect instead of treating the whole feature as a black box.
10 teaching examples
Example 1: Refactoring example
In a Timers Scheduling and Cancellation exercise, take code that mixes AbortController and Cancelled Work with unrelated business logic and split it into a small function with an explicit input and return value. The caller should not need to know low-level details unless they are part of the contract.
Example 2: Production reasoning
Assume the AbortController and Cancelled Work code from Chapter 16 runs thousands of times. Decide what needs a timeout, limit, retry rule, cleanup step, metric, or graceful-shutdown hook. The goal is predictable behavior under repetition, load, and partial failure.
Example 3: Minimal working case
In Chapter 16 (Timers Scheduling and Cancellation), build the smallest AbortController and Cancelled Work example that has one clear input and one visible result. Before running it, write what you expect to happen. Then verify inputs, observable output, error behavior, and the resource that the operation consumes. This establishes a baseline you can reason about.
Example 4: Change one input
For Chapter 16 (Timers Scheduling and Cancellation), keep the same program but change exactly one input related to AbortController and Cancelled Work. Compare the two outputs and explain why the change happened. This teaches cause and effect instead of memorizing syntax.
Example 5: Compare two approaches
Within Timers Scheduling and Cancellation, solve one tiny task twice: first with the most direct approach to AbortController and Cancelled Work, then with a reasonable alternative. Compare readability, error behavior, and resource use. Choose the version whose tradeoff matches the task.
Example 6: Failure you can recognize
For Timers Scheduling and Cancellation, create a safe failure involving AbortController and Cancelled Work, such as invalid data, a missing resource, a closed connection, or a rejected promise. Observe the error type and decide where the program should handle it rather than hiding it.
Example 7: Real service scenario
Imagine a small tutoring-service backend applying AbortController and Cancelled Work during Chapter 16 (Timers Scheduling and Cancellation). State what arrives from the caller, what the Node.js process must do, what it returns, and what must be logged if the operation fails.
Example 8: Security or trust check
In the Timers Scheduling and Cancellation context, treat one value used by AbortController and Cancelled Work as untrusted. Identify what must be validated, encoded, bounded, or refused before the value reaches a sensitive operation. Explain the consequence of trusting it blindly.
Example 9: Concurrency check
For Chapter 16, run or reason about two AbortController and Cancelled Work operations close together. Ask whether ordering matters, whether shared state can conflict, and whether work should be awaited, queued, streamed, or moved to another worker.
Example 10: Performance check
While studying Timers Scheduling and Cancellation, measure the resource most affected by AbortController and Cancelled Work: elapsed time, bytes, memory, open connections, event-loop delay, or database round trips. Optimize only after the measurement identifies a meaningful cost.
Node.js coding example
// Topic: AbortController and Cancelled Work
import { Readable } from 'node:stream';
import { pipeline } from 'node:stream/promises';
import { createWriteStream } from 'node:fs';
const source = Readable.from(['chapter 16\n', "AbortController and Cancelled Work\\n"]);
await pipeline(source, createWriteStream('node-topic-16-5.txt'));
console.log('saved');Step-by-step code explanation
- Create a readable stream from two small chunks.
- Create a writable file stream.
- Use pipeline so stream errors are propagated and cleanup is coordinated.
- Wait for completion before printing the confirmation.
Expected output: saved, and a small text file is created.
Practice exercise
Build a small Chapter 16 example for AbortController and Cancelled Work. Write the expected result before running it. Add one failure case, then change exactly one condition and explain why the behavior changed. For production reasoning, identify one limit, timeout, cleanup step, or validation rule that would make the code safer.
Chapter 16 review — 20 questions and answers
1. What is the main purpose of setTimeout?
Answer: Its purpose is to make setTimeout explicit and observable so the program can use it predictably rather than relying on hidden assumptions.
2. What should a beginner identify before using setTimeout?
Answer: Identify the input, expected output, completion signal, possible error, and any resource that must be released.
3. Why is error handling important for setTimeout?
Answer: Because real inputs and resources fail. Correct code defines how the failure is reported and what cleanup still must happen.
4. How can you test setTimeout safely?
Answer: Start with a tiny deterministic case, test one failure case, then add concurrency or untrusted input only after the baseline is understood.
5. What is the main purpose of setInterval?
Answer: Its purpose is to make setInterval explicit and observable so the program can use it predictably rather than relying on hidden assumptions.
6. What should a beginner identify before using setInterval?
Answer: Identify the input, expected output, completion signal, possible error, and any resource that must be released.
7. Why is error handling important for setInterval?
Answer: Because real inputs and resources fail. Correct code defines how the failure is reported and what cleanup still must happen.
8. How can you test setInterval safely?
Answer: Start with a tiny deterministic case, test one failure case, then add concurrency or untrusted input only after the baseline is understood.
9. What is the main purpose of setImmediate?
Answer: Its purpose is to make setImmediate explicit and observable so the program can use it predictably rather than relying on hidden assumptions.
10. What should a beginner identify before using setImmediate?
Answer: Identify the input, expected output, completion signal, possible error, and any resource that must be released.
11. Why is error handling important for setImmediate?
Answer: Because real inputs and resources fail. Correct code defines how the failure is reported and what cleanup still must happen.
12. How can you test setImmediate safely?
Answer: Start with a tiny deterministic case, test one failure case, then add concurrency or untrusted input only after the baseline is understood.
13. What is the main purpose of Promise-Based Timers?
Answer: Its purpose is to make Promise-Based Timers explicit and observable so the program can use it predictably rather than relying on hidden assumptions.
14. What should a beginner identify before using Promise-Based Timers?
Answer: Identify the input, expected output, completion signal, possible error, and any resource that must be released.
15. Why is error handling important for Promise-Based Timers?
Answer: Because real inputs and resources fail. Correct code defines how the failure is reported and what cleanup still must happen.
16. How can you test Promise-Based Timers safely?
Answer: Start with a tiny deterministic case, test one failure case, then add concurrency or untrusted input only after the baseline is understood.
17. What is the main purpose of AbortController and Cancelled Work?
Answer: Its purpose is to make AbortController and Cancelled Work explicit and observable so the program can use it predictably rather than relying on hidden assumptions.
18. What should a beginner identify before using AbortController and Cancelled Work?
Answer: Identify the input, expected output, completion signal, possible error, and any resource that must be released.
19. Why is error handling important for AbortController and Cancelled Work?
Answer: Because real inputs and resources fail. Correct code defines how the failure is reported and what cleanup still must happen.
20. How can you test AbortController and Cancelled Work safely?
Answer: Start with a tiny deterministic case, test one failure case, then add concurrency or untrusted input only after the baseline is understood.