Offers locking a mechanism to prevent race conditions.

interface ILockProvider {
    acquire<T>(
        key: string,
        callback: () => Promise<T>,
        options: { maxOccupationTime: number; timeout: number },
    ): Promise<T>;
}

Implemented by

Methods

Methods

  • Type Parameters

    • T

    Parameters

    • key: string

      the key of the resource to lock

    • callback: () => Promise<T>

      the code which should run once the lock was acquired

    • options: { maxOccupationTime: number; timeout: number }

    Returns Promise<T>

    'timeout' or 'occupation-time-exceed' errors