mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Update WrappedExpiringResourceLocker to new interface
Due to the new interface, it is now possible to throw an error if there is a timeout which should make it easier to find locking issues.
This commit is contained in:
@@ -1,7 +1,31 @@
|
||||
import type { ExpiringLock } from './ExpiringLock';
|
||||
import type { ResourceIdentifier } from '../../ldp/representation/ResourceIdentifier';
|
||||
import type { ResourceLocker } from './ResourceLocker';
|
||||
|
||||
/**
|
||||
* Interface for a factory of expiring locks.
|
||||
* A {@link ResourceLocker} where the locks expire after a given time.
|
||||
*/
|
||||
export interface ExpiringResourceLocker<T extends ExpiringLock = ExpiringLock> extends ResourceLocker<T> {}
|
||||
export interface ExpiringResourceLocker extends ResourceLocker {
|
||||
/**
|
||||
* As {@link ResourceLocker.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.
|
||||
*
|
||||
* @param identifier - Identifier of the resource that needs to be locked.
|
||||
* @param whileLocked - A function to execute while the resource is locked.
|
||||
* Receives a callback as input parameter to maintain the lock.
|
||||
*/
|
||||
withReadLock: <T>(identifier: ResourceIdentifier, whileLocked: (maintainLock: () => void) => T | Promise<T>)
|
||||
=> Promise<T>;
|
||||
|
||||
/**
|
||||
* As {@link ResourceLocker.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.
|
||||
*
|
||||
* @param identifier - Identifier of the resource that needs to be locked.
|
||||
* @param whileLocked - A function to execute while the resource is locked.
|
||||
* Receives a callback as input parameter to maintain the lock.
|
||||
*/
|
||||
withWriteLock: <T>(identifier: ResourceIdentifier, whileLocked: (maintainLock: () => void) => T | Promise<T>)
|
||||
=> Promise<T>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user