crnt - v0.0.31
    Preparing search index...

    Interface Semaphore

    interface Semaphore {
        acquire(
            options?: { priority?: number; signal?: AbortSignal; timeout?: number },
        ): Promise<SemaphorePermit>;
        maybeAcquire(): undefined | SemaphorePermit;
        release(): void;
        run<T>(
            fn: () => Promise<T>,
            options?: { priority?: number; signal?: AbortSignal; timeout?: number },
        ): Promise<T>;
    }
    Index

    Methods

    • asynchronously acquire a permit, waiting until one becomes available, or throw if aborted

      Parameters

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

          If provided, the acquire operation will be given priority over other operations.

          The default priority is 0.

        • Optionalsignal?: AbortSignal

          same signature as fetch(), but for aborting operations. If provided, the operation will be aborted when the signal is aborted.

        • Optionaltimeout?: number

          timeout in milliseconds. This works in tandem with the signal option, whichever triggers first (signal or timeout) will abort the operation.

      Returns Promise<SemaphorePermit>

    • release a permit, making it available for other operations

      Returns void

    • run a function with a semaphore, acquiring a permit before running and releasing it after

      Type Parameters

      • T

      Parameters

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

          If provided, the acquire operation will be given priority over other operations.

          The default priority is 0.

        • Optionalsignal?: AbortSignal

          same signature as fetch(), but for aborting operations. If provided, the operation will be aborted when the signal is aborted.

        • Optionaltimeout?: number

          timeout in milliseconds. This works in tandem with the signal option, whichever triggers first (signal or timeout) will abort the operation.

      Returns Promise<T>