mirror of https://github.com/nodejs/node.git
doc: update output of example in AbortController
Actual output of example in AbortController is mismatched. Plus, make `reason` parameter as optional in JSDoc. Refs: https://github.com/nodejs/node/blob/main/doc/api/globals.md#abortcontrollerabortreason Refs: https://github.com/nodejs/node/blob/main/doc/api/globals.md#static-method-abortsignalabortreason PR-URL: https://github.com/nodejs/node/pull/47227 Reviewed-By: Debadree Chatterjee <debadree333@gmail.com> Reviewed-By: Erick Wendel <erick.workspace@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
06c91af1b4
commit
6ed64e784a
|
@ -43,7 +43,7 @@ ac.signal.addEventListener('abort', () => console.log('Aborted!'),
|
|||
|
||||
ac.abort();
|
||||
|
||||
console.log(ac.signal.aborted); // Prints True
|
||||
console.log(ac.signal.aborted); // Prints true
|
||||
```
|
||||
|
||||
### `abortController.abort([reason])`
|
||||
|
@ -196,7 +196,7 @@ An optional reason specified when the `AbortSignal` was triggered.
|
|||
```js
|
||||
const ac = new AbortController();
|
||||
ac.abort(new Error('boom!'));
|
||||
console.log(ac.signal.reason); // Error('boom!');
|
||||
console.log(ac.signal.reason); // Error: boom!
|
||||
```
|
||||
|
||||
#### `abortSignal.throwIfAborted()`
|
||||
|
|
|
@ -163,7 +163,7 @@ class AbortSignal extends EventTarget {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {any} reason
|
||||
* @param {any} [reason]
|
||||
* @returns {AbortSignal}
|
||||
*/
|
||||
static abort(
|
||||
|
@ -326,7 +326,7 @@ class AbortController {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {any} reason
|
||||
* @param {any} [reason]
|
||||
*/
|
||||
abort(reason = new DOMException('This operation was aborted', 'AbortError')) {
|
||||
abortSignal(this.#signal ??= createAbortSignal(), reason);
|
||||
|
|
Loading…
Reference in New Issue