generated from MatrixAI/TypeScript-Demo-Lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Labels
developmentStandard developmentStandard developmentr&d:polykey:core activity 1Secret Vault Sharing and Secret History ManagementSecret Vault Sharing and Secret History Management
Description
Specification
If we need to be able to "retry" locking due to deadlocks MatrixAI/Polykey#294 (comment).
Then we would need to integrate the withTimeout
and tryAcquire
decorators from async-mutex
. They can be represented with parameters to our acquireRead
and acquireWrite
. But that would also mean we have to lambda-abstract them.
public read(timeout?: number): ResourceAcquire<RWLockWriter> {
// by default timeout: undefined
// but if 0, use tryAcquire
// if above 0, use withTimeout
return async () => {
// same contents as this.acquireRead()
};
}
Note that when timed out, an exception is thrown. We don't actually retry here. It is up to the user of the lock to attempt to call again, in case they need some random jitter delay.
We can keep the acquireRead
method if we want to preserve the API. Or expect users to just do this.read()
and this.write()
with the relevant timeouts.
Additional context
Tasks
- Import
withTimeout
andtryAcquire
fromasync-mutex
- Add in
read
andwrite
methods that have atimeout
parameter - Usage is now like
withF([rwLock.read(1000)], async ([lock]) => ...)
- Add timeout parameters to
withRead
andwithWrite
variants too as the second parameter afterf
andg
for function and generator variants.
Metadata
Metadata
Assignees
Labels
developmentStandard developmentStandard developmentr&d:polykey:core activity 1Secret Vault Sharing and Secret History ManagementSecret Vault Sharing and Secret History Management