Wraps around an existing ReadWriteLocker and adds expiration logic to prevent locks from getting stuck.

Hierarchy

  • WrappedExpiringReadWriteLocker

Implements

Constructors

Properties

expiration: number
logger: Logger = ...

Methods

  • Creates a Promise that either resolves the given input function or rejects if time runs out, whichever happens first. The input function can reset the timer by calling the maintainLock function it receives. The ResourceIdentifier is only used for logging.

    Type Parameters

    • T

    Parameters

    • identifier: ResourceIdentifier
    • whileLocked: ((maintainLock: (() => void)) => T | Promise<T>)
        • (maintainLock: (() => void)): T | Promise<T>
        • Parameters

          • maintainLock: (() => void)
              • (): void
              • Returns void

          Returns T | Promise<T>

    Returns Promise<T>

  • As withReadLock but the locked function gets called with a maintainLock callback function to reset the lock expiration every time it is called. The resulting promise will reject once the lock expires.

    Type Parameters

    • T

    Parameters

    • identifier: ResourceIdentifier

      Identifier of the resource that needs to be locked.

    • whileLocked: ((maintainLock: (() => void)) => T | Promise<T>)

      A function to execute while the resource is locked. Receives a callback as input parameter to maintain the lock.

        • (maintainLock: (() => void)): T | Promise<T>
        • Parameters

          • maintainLock: (() => void)
              • (): void
              • Returns void

          Returns T | Promise<T>

    Returns Promise<T>

  • As withWriteLock but the locked function gets called with a maintainLock callback function to reset the lock expiration every time it is called. The resulting promise will reject once the lock expires.

    Type Parameters

    • T

    Parameters

    • identifier: ResourceIdentifier

      Identifier of the resource that needs to be locked.

    • whileLocked: ((maintainLock: (() => void)) => T | Promise<T>)

      A function to execute while the resource is locked. Receives a callback as input parameter to maintain the lock.

        • (maintainLock: (() => void)): T | Promise<T>
        • Parameters

          • maintainLock: (() => void)
              • (): void
              • Returns void

          Returns T | Promise<T>

    Returns Promise<T>