Back-Off
Circuit Breaker design pattern for JavaScript
This module let's you use the Circuit Breaker pattern and call a function multiple times. In addition you can specify a delay to be applied between attempts as well as extending the delay as attempts are made.
Async/Await
const BackOff = require('back-off');
const backoff = new BackOff({
times: 5,
delay: 50,
backoff: true
});
try {
const result = await backoff.execute(asyncTask);
} catch (error) {
}
Promise
const BackOff = require('back-off');
const backoff = new BackOff({
times: 5,
delay: 50,
backoff: true
});
backoff.execute(() => {
})
.then(()=> {
})
.catch(() => {
});
The tests show the module in action.