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 checkwithLock(name, callback)โ runscallbackwhile holding the named lock; returns the callback's result
See the API reference for full signatures.