export interface LockfileOptions { debug?: any; timeout?: number; retryInterval?: number; } export interface LockOptions { reason?: string; ifLocked: ({reason}: { reason?: string; }) => Promise | void; timeout: number; retryInterval: number; } export default class Lockfile { base: string; timeout: number; retryInterval: number; stale: number; uuid: string; private fs; private _debug?; private _count; private updater?; /** * creates a new simple lockfile without read/write support */ constructor(base: string, options?: LockfileOptions); readonly count: number; readonly dirPath: string; /** * creates a lock * same as add */ lock(): Promise; /** * creates a lock * same as add */ lockSync(): void; /** * removes all lock counts */ unlock(): Promise; /** * removes all lock counts */ unlockSync(): void; /** * adds 1 lock count */ add(opts?: Partial): Promise; /** * adds 1 lock count */ addSync(opts?: { reason?: string; }): void; /** * removes 1 lock count */ remove(): Promise; /** * removes 1 lock count */ removeSync(): void; /** * check if this instance can get a lock * returns true if it already has a lock */ check(): Promise; /** * check if this instance can get a lock * returns true if it already has a lock */ checkSync(): boolean; private readonly _infoPath; private fetchReason(); private fetchReasonSync(); private _saveReason(reason); private _saveReasonSync(reason); private fetchMtime(); private fetchMtimeSync(); private isStale(mtime?); private debug(msg, ...args); private _add(opts); private _lock(opts); private _lockSync({reason, retries}?); private _status(mtime); private startLocking(); private _stopLocking(); private _debugReport(action, reason?); } export interface RWLockfileOptions { debug?: any; file?: string; }