Constructors

Properties

DEFAULT_MAX_OCCUPATION_TIME: number
DEFAULT_MAX_PENDING: number
DEFAULT_TIMEOUT: number

Methods

  • Lock on asynchronous code.

    Type Parameters

    • T

    Parameters

    Returns Promise<T>

    import AsyncLock = require('async-lock');
    const lock = new AsyncLock();

    lock.acquire(
    key,
    () => {
    // return value or promise
    },
    opts
    ).then(() => {
    // lock released
    });
  • Lock on asynchronous code.

    Type Parameters

    • T

    Parameters

    Returns void

    import AsyncLock = require('async-lock');
    const lock = new AsyncLock();

    lock.acquire(
    key,
    (done) => {
    // async work
    done(err, ret);
    },
    (err, ret) => {
    // lock released
    },
    opts
    );
  • Whether there is any running or pending async function.

    Parameters

    • Optionalkey: string

    Returns boolean