Allows the locking of resources which is needed for non-atomic ResourceStores.

Hierarchy

Implemented by

Properties

withReadLock: (<T>(identifier: ResourceIdentifier, whileLocked: (() => T | Promise<T>)) => Promise<T>)

Type declaration

    • <T>(identifier: ResourceIdentifier, whileLocked: (() => T | Promise<T>)): Promise<T>
    • Run the given function while the resource is locked. The lock will be released when the (async) input function resolves. This function should be used for operations that only require reading the resource.

      Returns

      A promise resolving when the lock is released.

      Type Parameters

      • T

      Parameters

      • identifier: ResourceIdentifier

        Identifier of the resource that needs to be locked.

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

        A function to execute while the resource is locked.

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

      Returns Promise<T>

withWriteLock: (<T>(identifier: ResourceIdentifier, whileLocked: (() => T | Promise<T>)) => Promise<T>)

Type declaration

    • <T>(identifier: ResourceIdentifier, whileLocked: (() => T | Promise<T>)): Promise<T>
    • Run the given function while the resource is locked. The lock will be released when the (async) input function resolves. This function should be used for operations that could modify the resource.

      Returns

      A promise resolving when the lock is released.

      Type Parameters

      • T

      Parameters

      • identifier: ResourceIdentifier

        Identifier of the resource that needs to be locked.

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

        A function to execute while the resource is locked.

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

      Returns Promise<T>