Skip to content
/ switch Public

A simple circuit breaker library to provide reliability

Notifications You must be signed in to change notification settings

nmjmdr/switch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Switch

A simple circuit breaker library to provide reliability

Example:

create(primaryFunction, secondaryFunction, onErrorTryOther, shouldProbe)

const cb = create(()=>{
  if(Math.random() < 0.5) {
    return Promise.reject("primary err");
  }else {
    return Promise.resolve("primary");
  }
},()=>{
  if(Math.random() < 0.2) {
    return Promise.reject("secondary err");
  }else {
    return Promise.resolve("secondary");
  }
},()=>{
  return true;
},(stats)=>{
  console.log(stats);
  return stats.callsToSecondary > 2;
});

cb([true])
.then((r)=>{
 console.log(r);
});

About

A simple circuit breaker library to provide reliability

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published