Upgrade Mutex to RWLock to enable `ready(undefined, true);` to mean blocking async operation
CMCDragonkai opened this issue · 1 comments
Specification
We can use RWLock so that when running certain ready operations, they actually block the start, stop, destroy.
To do this, we need to use read locks on all other operations, and write locks in start, stop, destroy.
It would only apply to async functions and async generators.
Releasing the lock would only happen at the end of the async generator.
async function* asyncGenerator() {
let i = 0;
while (i < 3) {
yield i++;
}
}
async function* testthis () {
try {
yield * asyncGenerator();
} finally {
console.log('done');
}
}
async function main () {
for await (const a of testthis()) {
console.log(a);
}
}
main();We would take the RWLock from js-polykey. However we need to upgrade it. We need to use the acquire and release API as the functional API doesn't always work. Such as for the async generators.
Additional context
- MatrixAI/Polykey#292 - The
composemethod can then use just useready(..., true);to indicate blocking operation.
It seems by default blocking can be true, since this is usually what you want, but it does change the semantics of all ready uses. Maybe that's ok. This can be integration tested by using npm link.
Tasks
- Upgrade RWLock with
acquireandreleaseAPI - Apply the
blockparameter instead ofwaitparameter - Test all decorators and decide whether it is block true or false by default
In the mean time, switch over the symbols to be in the common utilities and export them so that js-polykey can just import the symbols from one place if they want to access it.