Skip to content
Justice Tech School

Cancelling with AbortController

AbortController cancels fetches, timers and streams that accept a signal.

Example
const { setTimeout: sleep } = require("timers/promises");
const ac = new AbortController();
sleep(1000, null, { signal: ac.signal }).catch((e) => console.log(e.name));
ac.abort();

Result

AbortError

Exercise

Cancel.

ac.()

Quiz Test

What do you pass to cancel?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.