From 02cc0eeebd5d9cb9edad2ff5f7183f2586c6a3d4 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 --- doc/api/globals.md | 8 ++++++++ lib/internal/abort_controller.js | 15 +++++++++++++-- test/parallel/test-abortcontroller.js | 17 +++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/doc/api/globals.md b/doc/api/globals.md index 88e9aad9df21f8..6c8dde7ae10e0a 100644 --- a/doc/api/globals.md +++ b/doc/api/globals.md @@ -180,6 +180,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`