@bluelibs/runner - v5.5.0
    Preparing search index...

    Class Semaphore

    A semaphore that limits the number of concurrent operations. Used to prevent connection pool exhaustion by limiting concurrent database operations to the pool size.

    Index

    Constructors

    Methods

    • Acquire a permit. If no permits are available, waits until one becomes available.

      Parameters

      • Optionaloptions: { signal?: AbortSignal; timeout?: number }

      Returns Promise<void>

    • Dispose the semaphore, rejecting all waiting operations and preventing new ones.

      Returns void

    • Get current number of available permits (for debugging)

      Returns number

    • Get metrics about the current state of the semaphore

      Returns {
          availablePermits: number;
          disposed: boolean;
          maxPermits: number;
          utilization: number;
          waitingCount: number;
      }

    • Execute a function with a permit, automatically releasing it afterwards.

      Type Parameters

      • T

      Parameters

      • fn: () => Promise<T>
      • Optionaloptions: { signal?: AbortSignal; timeout?: number }

      Returns Promise<T>