Dev Helpers
← Back

Cancel a wait with an AbortSignal

Cancel a wait with an AbortSignal using Node.js.

Open this example in the interactive library

Source code

import {
  setTimeout as delay,
  setImmediate as immediate,
} from "node:timers/promises";
console.log(
  await delay(5, "ok", { signal: AbortSignal.abort() }).catch(
    (error) => error.name,
  ),
);

Sample output

AbortError