Skip to content

Commit

Permalink
lib: improve AbortController creation duration
Browse files Browse the repository at this point in the history
PR-URL: nodejs#45525
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
anonrig committed Jan 3, 2023
1 parent 2098d7a commit 911ea20
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/internal/abort_controller.js
Expand Up @@ -318,6 +318,8 @@ function validateAbortController(obj) {
}

class AbortController {
#signal;

constructor() {
this[kSignal] = createAbortSignal();
}
Expand All @@ -327,15 +329,16 @@ class AbortController {
*/
get signal() {
validateAbortController(this);
return this[kSignal];
this.#signal ??= createAbortSignal();
return this.#signal;
}

/**
* @param {any} reason
*/
abort(reason = new DOMException('This operation was aborted', 'AbortError')) {
validateAbortController(this);
abortSignal(this[kSignal], reason);
abortSignal(this.#signal ??= createAbortSignal(), reason);
}

[customInspectSymbol](depth, options) {
Expand Down

0 comments on commit 911ea20

Please sign in to comment.