From fde5e054ad93dfe9da06fcfb41724a97a222a247 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Wed, 24 Nov 2021 07:28:30 -0800 Subject: [PATCH] lib: add abortSignal.throwIfAborted() Refs: https://github.com/whatwg/dom/pull/1034 Signed-off-by: James M Snell PR-URL: https://github.com/nodejs/node/pull/40951 Reviewed-By: Benjamin Gruenbaum --- doc/api/globals.md | 8 ++++++++ lib/internal/abort_controller.js | 11 +++++++++-- test/parallel/test-abortcontroller.js | 23 +++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/doc/api/globals.md b/doc/api/globals.md index 3ec127ad1cb9b9..2c480fa6df7ba0 100644 --- a/doc/api/globals.md +++ b/doc/api/globals.md @@ -179,6 +179,14 @@ ac.abort(new Error('boom!')); console.log(ac.signal.reason); // Error('boom!'); ``` +#### `abortSignal.throwIfAborted()` + + + +If `abortSignal.aborted` is `true`, throws `abortSignal.reason`. + ## Class: `Buffer`