diff --git a/lib/circuit.js b/lib/circuit.js index 35fa0402..b2c60d8a 100644 --- a/lib/circuit.js +++ b/lib/circuit.js @@ -304,9 +304,7 @@ class CircuitBreaker extends EventEmitter { function _halfOpen (circuit) { circuit[STATE] = HALF_OPEN; circuit[PENDING_CLOSE] = true; - if (circuit.options.autoRenewAbortController) { - circuit.options.abortController = new AbortController(); - } + circuit._renewAbortControllerIfNeeded(); /** * Emitted after `options.resetTimeout` has elapsed, allowing for * a single attempt to call the service again. If that attempt is @@ -347,6 +345,21 @@ class CircuitBreaker extends EventEmitter { } } + /** + * Renews the abort controller if needed + * @private + * @returns {void} + */ + _renewAbortControllerIfNeeded () { + if ( + this.options.autoRenewAbortController && + this.options.abortController && + this.options.abortController.signal.aborted + ) { + this.options.abortController = new AbortController(); + } + } + /** * Closes the breaker, allowing the action to execute again * @fires CircuitBreaker#close @@ -359,13 +372,7 @@ class CircuitBreaker extends EventEmitter { } this[STATE] = CLOSED; this[PENDING_CLOSE] = false; - if ( - this.options.autoRenewAbortController && - this.options.abortController && - this.options.abortController.signal.aborted - ) { - this.options.abortController = new AbortController(); - } + this._renewAbortControllerIfNeeded(); /** * Emitted when the breaker is reset allowing the action to execute again * @event CircuitBreaker#close