Skip to content
Discussion options

You must be logged in to vote

Use retry for one operation that may recover after a few attempts. Use createCircuitBreaker when a dependency is failing repeatedly and you want to stop sending traffic for a recovery window.

In this package:

  • closed: calls go through normally.
  • open: calls fail fast with CircuitBreakerOpenError until recoveryTime passes.
  • half-open: the breaker allows test calls; enough successes closes it again.
import { createCircuitBreaker } from "@shnwazdeveloper/shnwazdev";

const breaker = createCircuitBreaker(
  () => fetch("https://api.example.com/health"),
  {
    failureThreshold: 3,
    recoveryTime: 30_000,
    successThreshold: 1,
    onStateChange(next, previous) {
      console.log({ previous,

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by clyxudev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants