From 4ba883d384ce269731f7dc34a0524871d02f3fe4 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 | 21 +++++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/doc/api/globals.md b/doc/api/globals.md index 3e47237714f306..9df487a786ac1e 100644 --- a/doc/api/globals.md +++ b/doc/api/globals.md @@ -191,6 +191,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`