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 authored and marco-ippolito committed Nov 23, 2022
1 parent 9d3c1da commit e1b7a3c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/internal/abort_controller.js
Original file line number Diff line number Diff line change
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 e1b7a3c

Please sign in to comment.