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.
Browser supportโ
| API | Chrome | Edge | Firefox | Safari | iOS Safari | Baseline |
|---|---|---|---|---|---|---|
LockManager.request | โ 69+ | โ 79+ | โ 96+ | โ 15.4+ | โ 15.4+ | Widely available |
โ
supported ยท โ partial ยท โ not supported ยท [n] see note. Generated from MDN browser-compat-data and web-features. caniuse: LockManager.request
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.