Adds CircuitBreaker#call() method
This allows the user to control the this
context within the function execution for a circuit. This method behaves in many ways like Function.prototype.call()
. It takes a this
context as the first parameter and any optional parameters as an argument list to the function. Here is an example usage:
const context = {
lunch: 'sushi'
};
async function getLunch (param) {
return param
? Promise.resolve(param)
: Promise.resolve(this.lunch);
}
getLunch.lunch = 'tacos';
const circuit = new CircuitBreaker(getLunch);
circuit.call()
.then(console.log) // logs 'tacos'
.then(_ => {
circuit.call(context)
.then(console.log) // logs 'sushi'
.then(_ => {
circuit.call(context, 'burgers')
.then(console.log); // logs 'burgers'
});
});