Circuit Breaker

Protect against cascading failures.

1 min readEdit this page

Usage

import { CircuitBreaker } from '@restjs/circuit'
 
const cb = new CircuitBreaker('payment', {
  failureThreshold: 5,
  resetTimeoutMs: 30000,
  fallback: () => ({ error: 'Unavailable' })
})
 
const result = await cb.execute(() => paymentService.charge(amount))

States

CLOSED → (failures) → OPEN → (timeout) → HALF_OPEN → success → CLOSED