Wraps an async operation with a circuit breaker.
Unique key for the breaker instance (e.g., "GET:/api/patients").
Function returning a Promise to protect.
Partial breaker configuration (optional).
The resolved value from the operation, or throws if the breaker is open.
// Protect a fetch call with a circuit breakerconst result = await wrapWithBreaker('GET:/api/patients', () => fetch('/api/patients')); Copy
// Protect a fetch call with a circuit breakerconst result = await wrapWithBreaker('GET:/api/patients', () => fetch('/api/patients'));
// Custom thresholdsconst data = await wrapWithBreaker('POST:/api/orders', () => postOrder(), { failureThreshold: 3, cooldownMs: 5000 }); Copy
// Custom thresholdsconst data = await wrapWithBreaker('POST:/api/orders', () => postOrder(), { failureThreshold: 3, cooldownMs: 5000 });
Wraps an async operation with a circuit breaker.