Skip to content
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

Allow making locks re-entrant #67

Open
jasnell opened this issue Dec 14, 2020 · 1 comment
Open

Allow making locks re-entrant #67

jasnell opened this issue Dec 14, 2020 · 1 comment

Comments

@jasnell
Copy link

jasnell commented Dec 14, 2020

Acquired locks are currently not reentrant...

navigator.locks.request('foo', async () => {
  navigator.locks.request('foo', async () => {
    // This will block...
  })
})

If an exclusive lock is requested by the same context that already owns the lock, it would be nice to have the ability for that to just work...

navigator.locks.request('foo', { reentrant: true }, async () => {
  navigator.locks.request('foo', async () => {
    // This would succeed.
  })
})

The above example is pretty silly, of course. The use case I'm considering are when the callback invoked comes from a different source, or some further down dependency is requesting the lock... e.g.

async function alsoHappensToRequestLock() {
  await navigator.locks.request('foo', async () => {
    // ...
  })
}

navigator.locks.request('foo', { reentrant: true }, async () => {
  await alsoHappensToRequestLock();
})
@annevk
Copy link
Member

annevk commented Dec 15, 2020

Unless I'm missing something, this would require careful testing to ensure this sharing depends on a clearly defined boundary and not something implementation-defined. I guess you want to compare agents.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants