Skip to content

Commit

Permalink
lib: improve AbortController creation duration
Browse files Browse the repository at this point in the history
PR-URL: #45525
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
anonrig authored and ruyadorno committed Nov 24, 2022
1 parent 16643db commit 5745bcb
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/internal/abort_controller.js
Expand Up @@ -309,20 +309,21 @@ function abortSignal(signal, reason) {
}

class AbortController {
#signal = createAbortSignal();
#signal;

/**
* @type {AbortSignal}
*/
get signal() {
this.#signal ??= createAbortSignal();
return this.#signal;
}

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

[customInspectSymbol](depth, options) {
Expand Down

0 comments on commit 5745bcb

Please sign in to comment.