diff --git a/lib/circuit.js b/lib/circuit.js index 2a541ded..c730634e 100644 --- a/lib/circuit.js +++ b/lib/circuit.js @@ -619,6 +619,13 @@ class CircuitBreaker extends EventEmitter { const args = rest.slice(); + /** + * Emitted when the circuit breaker action is executed + * @event CircuitBreaker#fire + * @type {any} the arguments passed to the fired function + */ + this.emit('fire', args); + // Protection, caches and coalesce disabled. if (!this[ENABLED]) { const result = this.action.apply(context, args); @@ -630,13 +637,6 @@ class CircuitBreaker extends EventEmitter { // Need to create variable here to prevent extra calls if cache is disabled let cacheKey = ''; - /** - * Emitted when the circuit breaker action is executed - * @event CircuitBreaker#fire - * @type {any} the arguments passed to the fired function - */ - this.emit('fire', args); - // If cache is enabled, check if we have a cached value if (this.options.cache) { cacheKey = this.options.cacheGetKey.apply(this, rest); diff --git a/test/enable-disable-test.js b/test/enable-disable-test.js index d76c178d..75c2be95 100644 --- a/test/enable-disable-test.js +++ b/test/enable-disable-test.js @@ -57,3 +57,16 @@ test('When disabled the circuit should always be closed', t => { .then(t.end); }); }); + +test('When disabled fire event is still emitted', t => { + t.plan(1); + const breaker = new CircuitBreaker(passFail); + breaker.on('fire', () => { + t.pass('fire event'); + t.end(); + }); + + breaker.disable(); + breaker.fire(1) + .finally(_ => breaker.shutdown()); +});