Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/live/deps.ts>supabase.navigatorLock

Open-Source web editor based on Preact, Tailwind and TypeScript. The other side of code.
Go to Latest
function supabase.navigatorLock
import { supabase } from "https://deno.land/x/live@1.60.4/deps.ts";
const { navigatorLock } = supabase;

Implements a global exclusive lock using the Navigator LockManager API. It is available on all browsers released after 2022-03-15 with Safari being the last one to release support. If the API is not available, this function will throw. Make sure you check availablility before configuring GoTrueClient.

You can turn on debugging by setting the supabase.gotrue-js.locks.debug local storage item to true.

Internals:

Since the LockManager API does not preserve stack traces for the async function passed in the request method, a trick is used where acquiring the lock releases a previously started promise to run the operation in the fn function. The lock waits for that promise to finish (with or without error), while the function will finally wait for the result anyway.

Parameters

name: string

Name of the lock to be acquired.

acquireTimeout: number

If negative, no timeout. If 0 an error is thrown if the lock can't be acquired without waiting. If positive, the lock acquire will time out after so many milliseconds. An error is a timeout if it has isAcquireTimeout set to true.

fn: () => Promise<R>

The operation to run once the lock is acquired.

Returns

Promise<R>