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
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.