From a4db29cb308b2965b9185e716614322f54467d2f Mon Sep 17 00:00:00 2001 From: Hamish Willee Date: Mon, 29 Mar 2021 14:55:45 +1100 Subject: [PATCH 1/9] Add AbortSignal.abort() static method --- .../web/api/abortsignal/abort/index.html | 50 +++++++++++++++++++ .../web/api/abortsignal/aborted/index.html | 4 +- files/en-us/web/api/abortsignal/index.html | 23 ++++++--- 3 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 files/en-us/web/api/abortsignal/abort/index.html diff --git a/files/en-us/web/api/abortsignal/abort/index.html b/files/en-us/web/api/abortsignal/abort/index.html new file mode 100644 index 000000000000000..c545ff07fdac922 --- /dev/null +++ b/files/en-us/web/api/abortsignal/abort/index.html @@ -0,0 +1,50 @@ +--- +title: AbortSignal.abort() +slug: Web/API/AbortSignal/abort +tags: + - API + - AbortSignal + - Method + - Reference + - abort +--- +
{{APIRef("DOM")}}
+ +

The static AbortSignal.abort() method returns an {{domxref("AbortSignal")}} that is already set as aborted (and which does trigger an abort event).

+ +

This is useful because the {{domxref("AbortSignal")}} is lazily created when first requested, and might not be called for until after the associated operation, for example an HTTP request, has already been aborted. This method allows code to return an aborted signal instance rather than an undefined object, or raising an exception.

+ +
+

Note

+

The method is similar in purpose to {{JSxRef("Promise.reject")}}

+
+ +

Syntax

+ +
AbortSignal.abort();
+ +

Return value

+ +

An AbortSignal instance with the {{domxref("AbortSignal.aborted")}} property set to true.

. + + +

Specifications

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('DOM WHATWG', '#interface-AbortSignal', 'AbortSignal')}}{{Spec2('DOM WHATWG')}}Initial definition
+ +

Browser compatibility

+ +

{{Compat("api.AbortSignal.abort")}}

diff --git a/files/en-us/web/api/abortsignal/aborted/index.html b/files/en-us/web/api/abortsignal/aborted/index.html index 4ed32312a2843d4..e5460daaaa368f0 100644 --- a/files/en-us/web/api/abortsignal/aborted/index.html +++ b/files/en-us/web/api/abortsignal/aborted/index.html @@ -11,7 +11,7 @@ ---
{{APIRef("DOM")}}
-

The aborted read-only property returns a {{domxref("Boolean")}} that indicates whether the DOM request(s) the signal is communicating with is/are aborted (true) or not (false).

+

The aborted read-only property returns a {{Glossary("Boolean")}} that indicates whether the DOM request(s) the signal is communicating with is/are aborted (true) or not (false).

Syntax

@@ -19,7 +19,7 @@

Syntax

Value

-

A {{domxref("Boolean")}}

+

A {{Glossary("Boolean")}}

Examples

diff --git a/files/en-us/web/api/abortsignal/index.html b/files/en-us/web/api/abortsignal/index.html index d68921f7d414896..91366031e6441ef 100644 --- a/files/en-us/web/api/abortsignal/index.html +++ b/files/en-us/web/api/abortsignal/index.html @@ -19,7 +19,7 @@

Properties

{{domxref("AbortSignal.aborted")}} {{readonlyInline}}
-
A {{domxref("Boolean")}} that indicates whether the request(s) the signal is communicating with is/are aborted (true) or not (false).
+
A {{jsxref("Boolean")}} that indicates whether the request(s) the signal is communicating with is/are aborted (true) or not (false).

Events

@@ -34,7 +34,16 @@

Events

Methods

-

The AbortSignal interface inherits methods from its parent interface, {{domxref("EventTarget")}}.

+

The AbortSignal interface inherits methods from its parent interface, {{domxref("EventTarget")}}.

+ + +

Static methods

+ +
+
{{domxref("AbortSignal.abort()")}}
+
Returns an AbortSignal instance that is already set as aborted.
+
+

Examples

@@ -66,12 +75,14 @@

Examples

  }) } -
-

Note: When abort() is called, the fetch() promise rejects with an AbortError.

+
+

Note

+

When abort() is called, the fetch() promise rejects with an AbortError.

-
-

Current version of Firefox rejects the promise with a DOMException

+
+

Warning

+

Current versions of Firefox rejects the promise with a DOMException

You can find a full working example on GitHub — see abort-api (see it running live also).

From 070b51e8b5c134e9b1e413f716d7c251cdf630de Mon Sep 17 00:00:00 2001 From: Hamish Willee Date: Tue, 30 Mar 2021 10:52:32 +1100 Subject: [PATCH 2/9] Does NOT trigger event --- files/en-us/web/api/abortsignal/abort/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/en-us/web/api/abortsignal/abort/index.html b/files/en-us/web/api/abortsignal/abort/index.html index c545ff07fdac922..6a21b5ada86453f 100644 --- a/files/en-us/web/api/abortsignal/abort/index.html +++ b/files/en-us/web/api/abortsignal/abort/index.html @@ -10,7 +10,7 @@ ---
{{APIRef("DOM")}}
-

The static AbortSignal.abort() method returns an {{domxref("AbortSignal")}} that is already set as aborted (and which does trigger an abort event).

+

The static AbortSignal.abort() method returns an {{domxref("AbortSignal")}} that is already set as aborted (and which does not trigger an abort event).

This is useful because the {{domxref("AbortSignal")}} is lazily created when first requested, and might not be called for until after the associated operation, for example an HTTP request, has already been aborted. This method allows code to return an aborted signal instance rather than an undefined object, or raising an exception.

From ffccd2e74f44f0fb712320ee9558886138b3f1ab Mon Sep 17 00:00:00 2001 From: Hamish Willee Date: Tue, 30 Mar 2021 10:53:45 +1100 Subject: [PATCH 3/9] improve wording --- files/en-us/web/api/abortsignal/abort/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/en-us/web/api/abortsignal/abort/index.html b/files/en-us/web/api/abortsignal/abort/index.html index 6a21b5ada86453f..fc0629864b76b3c 100644 --- a/files/en-us/web/api/abortsignal/abort/index.html +++ b/files/en-us/web/api/abortsignal/abort/index.html @@ -12,7 +12,7 @@

The static AbortSignal.abort() method returns an {{domxref("AbortSignal")}} that is already set as aborted (and which does not trigger an abort event).

-

This is useful because the {{domxref("AbortSignal")}} is lazily created when first requested, and might not be called for until after the associated operation, for example an HTTP request, has already been aborted. This method allows code to return an aborted signal instance rather than an undefined object, or raising an exception.

+

This is useful because the {{domxref("AbortSignal")}} is lazily created when first requested, and might not be accessed until after the associated operation has already been aborted (for example an HTTP request). This method allows code to return an aborted signal instance rather than an undefined object, or raising an exception.

Note

From ebf21bca41189481dd6553a34a0585e2d6e57ae8 Mon Sep 17 00:00:00 2001 From: Hamish Willee Date: Tue, 30 Mar 2021 10:54:35 +1100 Subject: [PATCH 4/9] Fix up {{Glossary("Boolean")}} --- files/en-us/web/api/abortsignal/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/en-us/web/api/abortsignal/index.html b/files/en-us/web/api/abortsignal/index.html index 91366031e6441ef..f2ef5374d9d26ec 100644 --- a/files/en-us/web/api/abortsignal/index.html +++ b/files/en-us/web/api/abortsignal/index.html @@ -19,7 +19,7 @@

Properties

{{domxref("AbortSignal.aborted")}} {{readonlyInline}}
-
A {{jsxref("Boolean")}} that indicates whether the request(s) the signal is communicating with is/are aborted (true) or not (false).
+
A {{Glossary("Boolean")}} that indicates whether the request(s) the signal is communicating with is/are aborted (true) or not (false).

Events

From 9f35e10360985d171171f8cec89c4cb14fe2e26e Mon Sep 17 00:00:00 2001 From: Hamish Willee Date: Tue, 13 Apr 2021 11:19:37 +1000 Subject: [PATCH 5/9] Remove old boolean text --- files/en-us/web/api/abortsignal/aborted/index.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/files/en-us/web/api/abortsignal/aborted/index.html b/files/en-us/web/api/abortsignal/aborted/index.html index e5460daaaa368f0..3e14223b4ec4027 100644 --- a/files/en-us/web/api/abortsignal/aborted/index.html +++ b/files/en-us/web/api/abortsignal/aborted/index.html @@ -11,19 +11,19 @@ ---
{{APIRef("DOM")}}
-

The aborted read-only property returns a {{Glossary("Boolean")}} that indicates whether the DOM request(s) the signal is communicating with is/are aborted (true) or not (false).

+

The aborted read-only property returns a value that indicates whether the DOM request(s) the signal is communicating with is/are aborted (true) or not (false).

Syntax

-
var isAborted = abortSignal.aborted;
+
abortSignal.aborted;

Value

-

A {{Glossary("Boolean")}}

+

true (aborted) or false

Examples

-

In the following snippet, we create a new AbortController object, and get its {{domxref("AbortSignal")}} (available in the signal property). Later on we check whether or not it the signal has been aborted using the aborted property, and send an appropriate log to the console.

+

In the following snippet, we create a new AbortController object, and get its {{domxref("AbortSignal")}} (available in the signal property). Later on we check whether or not the signal has been aborted using the aborted property, and send an appropriate log to the console.

var controller = new AbortController();
 var signal = controller.signal;

From 78e63254e8bb2a5c50087ea05aaff341449cd8f4 Mon Sep 17 00:00:00 2001
From: Hamish Willee 
Date: Fri, 16 Apr 2021 17:06:10 +1000
Subject: [PATCH 6/9] Clarify when it might be useful

---
 files/en-us/web/api/abortsignal/abort/index.html | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/files/en-us/web/api/abortsignal/abort/index.html b/files/en-us/web/api/abortsignal/abort/index.html
index fc0629864b76b3c..3d32ad8a4ee7bc3 100644
--- a/files/en-us/web/api/abortsignal/abort/index.html
+++ b/files/en-us/web/api/abortsignal/abort/index.html
@@ -12,7 +12,13 @@
 
 

The static AbortSignal.abort() method returns an {{domxref("AbortSignal")}} that is already set as aborted (and which does not trigger an abort event).

-

This is useful because the {{domxref("AbortSignal")}} is lazily created when first requested, and might not be accessed until after the associated operation has already been aborted (for example an HTTP request). This method allows code to return an aborted signal instance rather than an undefined object, or raising an exception.

+

This is shorthand for the following code:

+ +
const controller = new AbortController();
+  controller.abort();
+  return controller.signal;
+ +

This could, for example, be passed to a fetch method in order to run its abort logic (i.e. it may be that code is organised such that this code should be run even if the intended fetch operation has not been started).

Note

From 2244fbdfa668177118b3675c37a52bf7758af753 Mon Sep 17 00:00:00 2001 From: Hamish Willee Date: Fri, 16 Apr 2021 17:08:51 +1000 Subject: [PATCH 7/9] FF88 relnotes - remove why this is useful --- files/en-us/mozilla/firefox/releases/88/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/en-us/mozilla/firefox/releases/88/index.html b/files/en-us/mozilla/firefox/releases/88/index.html index 903824f9e9411de..9e22d9873c54c51 100644 --- a/files/en-us/mozilla/firefox/releases/88/index.html +++ b/files/en-us/mozilla/firefox/releases/88/index.html @@ -69,7 +69,7 @@

APIs

DOM

    -
  • Code can now use the new static method AbortSignal.abort() to return an {{domxref("AbortSignal")}} that is already set as aborted. This is useful when the signal is requested/created after the associated operation has already been aborted. For more information see {{bug(1698468)}}.
  • +
  • Code can now use the new static method AbortSignal.abort() to return an {{domxref("AbortSignal")}} that is already set as aborted. For more information see {{bug(1698468)}}.

Media, WebRTC, and Web Audio

From 4d6a8e224b1e0ac7217d8263905eeb57d2c86074 Mon Sep 17 00:00:00 2001 From: Hamish Willee Date: Fri, 16 Apr 2021 17:11:58 +1000 Subject: [PATCH 8/9] Layout typo --- files/en-us/web/api/abortsignal/abort/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/en-us/web/api/abortsignal/abort/index.html b/files/en-us/web/api/abortsignal/abort/index.html index 3d32ad8a4ee7bc3..a83d56c7110ecf9 100644 --- a/files/en-us/web/api/abortsignal/abort/index.html +++ b/files/en-us/web/api/abortsignal/abort/index.html @@ -15,8 +15,8 @@

This is shorthand for the following code:

const controller = new AbortController();
-  controller.abort();
-  return controller.signal;
+controller.abort(); +return controller.signal;

This could, for example, be passed to a fetch method in order to run its abort logic (i.e. it may be that code is organised such that this code should be run even if the intended fetch operation has not been started).

From 11b6480c1a492cccc86e42c3381290a6e5c1e739 Mon Sep 17 00:00:00 2001 From: Hamish Willee Date: Fri, 16 Apr 2021 17:17:06 +1000 Subject: [PATCH 9/9] improve wording --- files/en-us/web/api/abortsignal/abort/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/en-us/web/api/abortsignal/abort/index.html b/files/en-us/web/api/abortsignal/abort/index.html index a83d56c7110ecf9..afe8602d2e3b101 100644 --- a/files/en-us/web/api/abortsignal/abort/index.html +++ b/files/en-us/web/api/abortsignal/abort/index.html @@ -18,7 +18,7 @@ controller.abort(); return controller.signal; -

This could, for example, be passed to a fetch method in order to run its abort logic (i.e. it may be that code is organised such that this code should be run even if the intended fetch operation has not been started).

+

This could, for example, be passed to a fetch method in order to run its abort logic (i.e. it may be that code is organised such that the abort logic should be run even if the intended fetch operation has not been started).

Note