Hierarchy (view full)

Constructors - Functional

Methods

Constructors - Functional

  • Semaphore implementation for async js operations, used for resource limit or pool implementation

    Parameters

    • count: number
    • defaultAcquireTimeout: number = -1

    Returns Semaphore

    5.15.0

    const sem = new Semaphore(10)

    async call_api(payload: any) {
    const release = await sem.acquire()
    // ...
    // this block, will be execute with 10 concurrency limit
    release()
    }

Methods

  • acquire a permit from sem

    Parameters

    • timeout: number = ...

      wait before timeout, if not set, will wait forever

    Returns Promise<ReleaseFunction>

    release function, which used for release a permit to sem

  • run an async function with sem limit

    Type Parameters

    • T

    Parameters

    • f: (() => Promise<T>)

      async runner function

        • (): Promise<T>
        • Returns Promise<T>

    • timeout: number = ...

      wait timeout before wait

    Returns Promise<T>