Skip to content

Allow making locks re-entrant #67

@jasnell

Description

@jasnell

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();
})

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions