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 and tryAcquire from async-mutex
- Add in
read and write methods that have a timeout parameter
- Usage is now like
withF([rwLock.read(1000)], async ([lock]) => ...)
- Add timeout parameters to
withRead and withWrite variants too as the second parameter after f and g for function and generator variants.
Specification
If we need to be able to "retry" locking due to deadlocks MatrixAI/Polykey#294 (comment).
Then we would need to integrate the
withTimeoutandtryAcquiredecorators fromasync-mutex. They can be represented with parameters to ouracquireReadandacquireWrite. But that would also mean we have to lambda-abstract them.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
acquireReadmethod if we want to preserve the API. Or expect users to just dothis.read()andthis.write()with the relevant timeouts.Additional context
Tasks
withTimeoutandtryAcquirefromasync-mutexreadandwritemethods that have atimeoutparameterwithF([rwLock.read(1000)], async ([lock]) => ...)withReadandwithWritevariants too as the second parameter afterfandgfor function and generator variants.