@vgerbot/async
    Preparing search index...

    Class CircuitBreakerExecutor

    A task executor implementing the circuit breaker pattern. Prevents cascading failures by failing fast when a service is unavailable.

    States:

    • CLOSED: Normal operation
    • OPEN: Service unavailable, fail immediately
    • HALF_OPEN: Testing recovery, allow limited requests
    const executor = new CircuitBreakerExecutor({
    failureThreshold: 3,
    resetTimeout: 5000,
    halfOpenRequests: 2,
    });

    try {
    await executor.exec(async () => {
    return await fetch('/api/data');
    });
    } catch (error) {
    if (executor.getState() === 'OPEN') {
    console.log('Circuit is open, service unavailable');
    }
    }

    Hierarchy (View Summary)

    Index

    Constructors

    Methods

    • Checks if the executor is shut down and throws ExecutorShutdownError if so. Subclasses should call this at the start of exec().

      Parameters

      • message: string = "Executor permanently shut down"

        Optional custom error message

      Returns void

      if the executor is shut down