Skip to content

Commit

Permalink
feat: return 'this' from CircuitBreaker.fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
lance committed Dec 6, 2016
1 parent 5ddcbc4 commit 159c006
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/circuit.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class CircuitBreaker extends EventEmitter {
*/
fallback (func) {
this[FALLBACK_FUNCTION] = func;
return this;
}

/**
Expand Down
11 changes: 11 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,17 @@ test('Passes arguments to the fallback function', (t) => {
});
});

test('Returns self from fallback()', (t) => {
circuitBreaker(passFail, { maxFailures: 1 })
.fallback(() => {})
.fire(1)
.then((result) => {
t.equals(result, 1);
})
.then(t.end)
.catch(t.fail);
});

test('CircuitBreaker status', (t) => {
const breaker = circuitBreaker(passFail, { maxFailures: 1 });
const deepEqual = (t, expected) => (actual) => t.deepEqual(actual, expected);
Expand Down

0 comments on commit 159c006

Please sign in to comment.