Skip to main content
Openfuse
Reference

BreakerHandle

API reference for the BreakerHandle class

A BreakerHandle is returned by client.breaker(slug). It delegates all operations to the parent client.

const stripe = client.breaker('stripe-api')

Properties

slug

readonly slug: string

The breaker slug this handle is bound to.


Methods

protect()

protect<T>(
  fn: (signal: AbortSignal) => Promise<T> | T,
  options?: TProtectOptions<T>,
): Promise<T>

Executes fn with circuit breaker protection. Checks breaker state, records metrics, and supports timeouts and fallbacks.

Parameters

ParameterTypeDescription
fn(signal: AbortSignal) => Promise<T> | TThe function to protect. Receives an AbortSignal for cooperative cancellation.
optionsTProtectOptions<T>Timeout, fallback, and signal configuration.

TProtectOptions

type TProtectOptions<T> = {
  timeout?: number
  fallback?: () => Promise<T> | T
  signal?: AbortSignal
}
OptionTypeDescription
timeoutnumberTimeout in milliseconds. Throws TimeoutError if exceeded.
fallback() => Promise<T> | TCalled when the breaker is open instead of fn. Not wrapped with timeout or signal.
signalAbortSignalExternal cancellation signal. Throws AbortOperationError when aborted.

Behavior

  • Breaker closed/half-open: fn executes. Metrics are recorded.
  • Breaker open + fallback: Fallback executes. No metrics recorded.
  • Breaker open + no fallback: fn executes with a warning logged (fail-open). Metrics are recorded.
  • State unknown: fn executes (fail-open). Metrics are recorded.

Throws

  • TimeoutError if fn exceeds timeout.
  • AbortOperationError if signal is aborted.
  • Any error thrown by fn is rethrown.
const charge = await stripe.protect(
  async (signal) => {
    return await paymentApi.charge({ amount: 1000 }, { signal })
  },
  {
    timeout: 5000,
    fallback: () => ({ status: 'queued' }),
  },
)

isOpen()

isOpen(): Promise<boolean>

Returns true if the breaker is open. Returns false if closed, half-open, unknown, or on any error. Never throws. Has a 500ms budget.

if (await stripe.isOpen()) {
  return cachedResponse
}

isClosed()

isClosed(): Promise<boolean>

Returns true if the breaker is closed. Returns true on any error (fail-open). Never throws. Has a 500ms budget.

if (await stripe.isClosed()) {
  // Safe to proceed
}

status()

status(signal?: AbortSignal): Promise<TBreaker | null>

Returns the full breaker object or null if not found or unreachable. Never throws. Has a 500ms budget.

ParameterTypeDescription
signalAbortSignalOptional cancellation signal.
const breaker = await stripe.status()
if (breaker) {
  console.log(breaker.state)
  console.log(breaker.updatedAt)
  console.log(breaker.retryAfter)
}

On this page