Interface ReadWriteLocker

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

interface ReadWriteLocker {
    withReadLock: (<T>(identifier: ResourceIdentifier, whileLocked: (() => PromiseOrValue<T>)) => Promise<T>);
    withWriteLock: (<T>(identifier: ResourceIdentifier, whileLocked: (() => PromiseOrValue<T>)) => Promise<T>);
}

Hierarchy (view full)

Implemented by

Properties

withReadLock: (<T>(identifier: ResourceIdentifier, whileLocked: (() => PromiseOrValue<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.

Type declaration

    • <T>(identifier, whileLocked): Promise<T>
    • Type Parameters

      • T

      Parameters

      Returns Promise<T>

      A promise resolving when the lock is released.

withWriteLock: (<T>(identifier: ResourceIdentifier, whileLocked: (() => PromiseOrValue<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.

Type declaration

    • <T>(identifier, whileLocked): Promise<T>
    • Type Parameters

      • T

      Parameters

      Returns Promise<T>

      A promise resolving when the lock is released.