Skip to content

Commit 29fa2da

Browse files
committed
lib: improve AbortController creation duration
PR-URL: nodejs#45525 Backport-PR-URL: nodejs#46078 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 2098d7a commit 29fa2da

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/internal/abort_controller.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ function validateAbortController(obj) {
318318
}
319319

320320
class AbortController {
321+
#signal;
322+
321323
constructor() {
322324
this[kSignal] = createAbortSignal();
323325
}
@@ -327,15 +329,16 @@ class AbortController {
327329
*/
328330
get signal() {
329331
validateAbortController(this);
330-
return this[kSignal];
332+
this.#signal ??= createAbortSignal();
333+
return this.#signal;
331334
}
332335

333336
/**
334337
* @param {any} reason
335338
*/
336339
abort(reason = new DOMException('This operation was aborted', 'AbortError')) {
337340
validateAbortController(this);
338-
abortSignal(this[kSignal], reason);
341+
abortSignal(this.#signal ??= createAbortSignal(), reason);
339342
}
340343

341344
[customInspectSymbol](depth, options) {

0 commit comments

Comments
 (0)