Protected
getGenerate the identifier that will be used to acquire the count lock for the given identifier.
There will be cases where this lock needs to be acquired
while an active lock on the main resource is still being maintained.
This means that if the input resourceLocker
and countLocker
use the same locking system
this generated identifier needs to be different.
Protected
modifyUpdate the counter that keeps track of having open read locks there currently are.
Identifier on which to update the number of read locks.
+1
or -1
.
Protected
withAcquires a new lock for the requested identifier. Will resolve when the input function resolves.
Identifier of resource that needs to be locked.
Function to resolve while the resource is locked.
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.
Identifier of the resource that needs to be locked.
A function to execute while the resource is locked.
A promise resolving when the lock is released.
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.
Identifier of the resource that needs to be locked.
A function to execute while the resource is locked.
A promise resolving when the lock is released.
A BaseReadWriteLocker that stores the counter and its associated locks in memory. The consequence of this is that multiple read requests are possible as long as they occur on the same worker thread. A read request from a different worker thread will have to wait until those from the current worker thread are finished.
The main reason for this class is due to the file locker that we use only allowing locks to be released by the same worker thread that acquired them.