Mutex, the mutex implementation for async operations

Hierarchy

Constructors - Functional

Methods

Functional Constructors

  • Mutex, the mutex implementation for async operations

    Since

    5.15.0

    Example

     const mut = new Mutex()

    async call_api(payload: any) {
    const release = await mut.acquire()
    try {
    // ...
    // this block, will be executed exclusively
    } finally {
    release() // release the mutex
    }
    }

    Parameters

    • defaultAcquireTimeout: number = -1

    Returns Mutex

Methods

  • acquire a permit from sem

    Returns

    release function, which used for release a permit to sem

    Parameters

    • timeout: number = ...

      wait before timeout, if not set, will wait forever

    Returns Promise<ReleaseFunction>

  • run an async function with sem limit

    Returns

    Type Parameters

    • T

    Parameters

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

      async runner function

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

    • timeout: number = ...

      wait timeout before wait

    Returns Promise<T>