Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement: stop keeping a set of all circuits #365

Merged
merged 1 commit into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions lib/circuit.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const WARMING_UP = Symbol('warming-up');
const VOLUME_THRESHOLD = Symbol('volume-threshold');
const deprecation = `options.maxFailures is deprecated. \
Please use options.errorThresholdPercentage`;
const CIRCUITS = new Set();

/**
* Constructs a {@link CircuitBreaker}.
Expand Down Expand Up @@ -175,8 +174,6 @@ class CircuitBreaker extends EventEmitter {
if (this.options.cache) {
CACHE.set(this, undefined);
}

CIRCUITS.add(this);
}

/**
Expand Down Expand Up @@ -226,7 +223,6 @@ class CircuitBreaker extends EventEmitter {
this.removeAllListeners();
this.status.shutdown();
this[STATE] = SHUTDOWN;
CIRCUITS.delete(this);
/**
* Emitted when the circuit breaker has been shut down.
* @event CircuitBreaker#shutdown
Expand Down Expand Up @@ -632,15 +628,4 @@ const nextName = () =>
return v.toString(16);
});

/**
* Gets a Set iterator of all active circuits. If a circuit
* has been created, but subsequently shut down, it will not
* be included in the Set iterator.
*
* @returns {Iterator} an Iterator object containing a reference
* to all {CircuitBreaker} instances that have been created.
*/
CircuitBreaker.circuits = function circuits() {
return CIRCUITS.values();
}
module.exports = exports = CircuitBreaker;
23 changes: 0 additions & 23 deletions test/circuit-shutdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,3 @@ test('Circuit shuts down properly', t => {
t.end();
});
});

test('A list of non-shutdown circuits is maintained', t => {
function expectCount(iterator, count) {
// eslint-disable-next-line no-empty-pattern
for (let {} of iterator) count--;
return count === 0;
}

t.ok(expectCount(CircuitBreaker.circuits(), 0));

const c1 = new CircuitBreaker(passFail);
const c2 = new CircuitBreaker(passFail);

t.ok(expectCount(CircuitBreaker.circuits(), 2));

c2.shutdown();
t.ok(expectCount(CircuitBreaker.circuits(), 1));

c1.shutdown();
t.ok(expectCount(CircuitBreaker.circuits(), 0));

t.end();
});