Skip to main content

@rtorcato/browser-common / weblocks

weblocks

Functions

withLock()

withLock<T>(name, callback): Promise<T>

Defined in: weblocks/index.ts:13

Runs a callback while holding a named lock using the Web Locks API.

Type Parameters

T

T

Parameters

name

string

The name of the lock.

callback

() => Promise<T>

The async function to run while holding the lock.

Returns

Promise<T>

The result of the callback.

Throws

If the Web Locks API is not supported.

Example

import { withLock } from '@rtorcato/browser-common/weblocks'
const result = await withLock('sync', async () => fetchAndStore())

isWebLocksAvailable()

isWebLocksAvailable(): boolean

Defined in: weblocks/index.ts:30

Checks if the Web Locks API is available in the current browser.

Returns

boolean

Example

import { isWebLocksAvailable } from '@rtorcato/browser-common/weblocks'
if (isWebLocksAvailable()) acquireLock()