Open this example in the interactive library
Source code
import { setTimeout } from "node:timers/promises";
const controller = new AbortController();
const timer = setTimeout(1000, "done", { signal: controller.signal });
controller.abort();
try {
await timer;
} catch (error) {
console.log(error.name);
}
Sample output
AbortError
