From e8989b688c32d12519783fcd900ea9992e6ec2b6 Mon Sep 17 00:00:00 2001 From: Helio Frota <00hf11@gmail.com> Date: Fri, 11 Sep 2020 13:06:39 -0300 Subject: [PATCH] fix: Adding docs about fallback parameters (#460) fixes #459 --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index d57f8890..2709f33e 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,21 @@ the `open` state. When a fallback function is triggered, it's considered a failure, and the fallback function will continue to be executed until the breaker is closed. +The fallback function accepts the same parameters as the fire function: + +```javascript +const delay = (delay, a, b, c) => + new Promise((resolve) => { + setTimeout(() => { + resolve(); + }, delay); + }); + +const breaker = new CircuitBreaker(delay); +breaker.fire(20000, 1, 2, 3); +breaker.fallback((delay, a, b, c) => `Sorry, out of service right now. But your parameters are: ${delay}, ${a}, ${b} and ${c}`); +``` + ### Browser Opossum really shines in a browser. You can use it to guard against network