Skip to content

Commit e8989b6

Browse files
authored
fix: Adding docs about fallback parameters (#460)
fixes #459
1 parent 2d4318d commit e8989b6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,21 @@ the `open` state.
7676
When a fallback function is triggered, it's considered a failure, and the
7777
fallback function will continue to be executed until the breaker is closed.
7878

79+
The fallback function accepts the same parameters as the fire function:
80+
81+
```javascript
82+
const delay = (delay, a, b, c) =>
83+
new Promise((resolve) => {
84+
setTimeout(() => {
85+
resolve();
86+
}, delay);
87+
});
88+
89+
const breaker = new CircuitBreaker(delay);
90+
breaker.fire(20000, 1, 2, 3);
91+
breaker.fallback((delay, a, b, c) => `Sorry, out of service right now. But your parameters are: ${delay}, ${a}, ${b} and ${c}`);
92+
```
93+
7994
### Browser
8095

8196
Opossum really shines in a browser. You can use it to guard against network

0 commit comments

Comments
 (0)