Skip to main content

weblocks

Coordinate work across tabs and workers with a named, async lock via the Web Locks API.

Import: @rtorcato/browser-common/weblocks

๐Ÿ“– MDN: Web Locks API ยท ๐Ÿ“Š caniuse: weblocks

Web Locks API needs a secure context. withLock throws where unsupported โ€” guard with isWebLocksAvailable() first.

Exampleโ€‹

import { isWebLocksAvailable, withLock } from '@rtorcato/browser-common/weblocks'

if (isWebLocksAvailable()) {
const result = await withLock('sync', async () => fetchAndStore())
}

Exportsโ€‹

  • isWebLocksAvailable() โ€” feature check
  • withLock(name, callback) โ€” runs callback while holding the named lock; returns the callback's result

See the API reference for full signatures.