alepha@docs:~/docs/reference/primitives$
cat $circuit.md1 min read
#$circuit
#Import
typescript
1import { $circuit } from "alepha/server";
#Overview
Consecutive failures before opening the circuit. */ threshold: number;
/**
- Cooldown before transitioning from open to half-open. */ reset: DurationLike; }
/** Middleware that implements the circuit breaker pattern.
Three states:
- Closed (normal) — calls pass through. Failures are counted.
- Open (tripped) — calls are immediately rejected. No handler execution.
- Half-open (probing) — one call is allowed. Success closes, failure re-opens.
typescript
1class PaymentController {2 charge = $action({3 use: [$circuit({ threshold: 5, reset: [30, "seconds"] })],4 handler: async ({ body }) => this.paymentGateway.charge(body),5 });6}
#Options
| Option | Type | Required | Description |
|---|---|---|---|
threshold |
number |
Yes | Consecutive failures before opening the circuit. |
reset |
DurationLike |
Yes | Cooldown before transitioning from open to half-open. |