Constructors

Properties

DEFAULT_MAX_OCCUPATION_TIME: number
DEFAULT_MAX_PENDING: number
DEFAULT_TIMEOUT: number

Methods

  • Lock on asynchronous code.

    Type Parameters

    • T

    Parameters

    • key: string | string[]

      resource key or keys to lock

    • fn: (() => T | PromiseLike<T>) | ((done) => any)

      function to execute

    • Optional opts: AsyncLockOptions

      options

    Returns Promise<T>

    Example

    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

    Example

    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

    • Optional key: string

    Returns boolean

Generated using TypeDoc