-
Notifications
You must be signed in to change notification settings - Fork 35
WIP: Web Locks API initial implementation #417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
@tshemsedinov isn't it supposed to be compliant with the spec for Web Locks API? It defines two interfaces: |
|
Yes, but it's just proof of concept and WIP. @belochub I'll implement also |
8422a3b to
e4d9e46
Compare
| const prev = Atomics.exchange(this.flag, 0, LOCKED); | ||
| if (prev === LOCKED) return; | ||
| this.owner = true; | ||
| this.trying = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this.trying needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use mutex.queue.length > 0 instead
| return this.tryEnter(); | ||
| } | ||
|
|
||
| tryEnter() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we can merge tryEnter and enterIfAvailable by adding lock argument and a few checks?
lib/locks.js
Outdated
| enterIfAvailable(lock) { | ||
| if (this.owner) return lock.callback(); | ||
| const prev = Atomics.exchange(this.flag, 0, LOCKED); | ||
| if (prev === LOCKED) return lock.callback(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to https://wicg.github.io/web-locks/#api-lock-manager-request when ifAvailable is true the callback must be passed a lock (boolean) argument that signifies whether it got the lock or not.
465e50b to
18bcd04
Compare
6c4674d to
92b1739
Compare
|
In new implementation:
|
618e7a5 to
c048cf2
Compare
Refs: #416