export declare const DEFAULT_EXPIRY: number; export interface Options { /** * The delay in ms before a lock expires. * * This delay exists to ensure that locks held by tabs which have since been * closed or are frozen (eg. for performance reasons) do not prevent other * tabs from acquiring the lock. * * Defaults to DEFAULT_EXPIRY */ expiry?: number; /** * The name of the object store in the database to use. * * If an existing database is passed to the constructor, that database must * have an object store of this name. * * Defaults to 'mutexes'. */ objectStoreName?: string; /** * The amount of time to wait in ms between attempts to lock if the lock is * contended. * * Note that `lock()` does not spin at all if the lock is not currently held. * * Defaults to 50ms. */ spinDelay?: number; } /** * A mutex for coordinating cross-tab activities. */ export default class Mutex { private _db; private _objectStoreName; private _name; private _id; private _expiry; private _spinDelay; /** * Initialize the mutex. * * @param name - Name of the mutex. * @param db - Existing database to use. If null, an IndexedDB database named * 'idb-mutex' is created. If an existing database is provided it must have * an object store name matching `options.objectStoreName`. * @param options */ constructor(name: string, db?: Promise | null, options?: Options); /** * Acquire the lock. * * If no other instance currently holds the lock, the previous lock has expired * or the current instance already holds the lock, then this resolves * immediately. * * Otherwise `lock()` waits until the current lock owner releases the lock or * it expires. * * Returns a Promise that resolves when the lock has been acquired. */ lock(): Promise; /** * Release the lock. * * Releases the lock, regardless of who currently owns it or whether it is * currently locked. */ unlock(): Promise<{}>; private _initDb(objectStoreName); private _tryLock(); }