Skip to content

Commit

Permalink
doc: update output of example in AbortController
Browse files Browse the repository at this point in the history
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: #47227
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
Reviewed-By: Erick Wendel <erick.workspace@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
deokjinkim authored and RafaelGSS committed Apr 7, 2023
1 parent 22b9acd commit a21459e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions doc/api/globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])`
Expand Down Expand Up @@ -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()`
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/abort_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class AbortSignal extends EventTarget {
}

/**
* @param {any} reason
* @param {any} [reason]
* @returns {AbortSignal}
*/
static abort(
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a21459e

Please sign in to comment.