export interface LockFs { mkdirSync(p: string, opts?: { recursive?: boolean; }): unknown; writeFileSync(p: string, data: string): void; readFileSync(p: string): string | Buffer; rmSync(p: string, opts?: { recursive?: boolean; force?: boolean; }): void; renameSync(from: string, to: string): void; } export interface LockDeps { fs?: LockFs; now?: () => number; sleep?: (ms: number) => Promise; pid?: number; hostname?: string; /** Whether a pid is alive on THIS host (only consulted for same-hostname metadata). */ isPidAlive?: (pid: number) => boolean; /** Start a repeating timer; returns a stop function. Default: unref'd setInterval. */ startInterval?: (fn: () => void, ms: number) => () => void; } export interface AcquireLockOptions { /** The lock directory itself (created exclusively; its existence IS the lock). */ dir: string; /** Max time to wait for the lock before giving up (default 10 min). */ waitMs?: number; /** Poll interval while waiting (default 1 s). */ pollMs?: number; /** Holder heartbeat refresh interval (default 30 s). */ heartbeatMs?: number; /** Heartbeat age beyond which a contender may take over (default 5 min). */ staleMs?: number; deps?: LockDeps; } export interface LockHandle { /** Stop the heartbeat and remove the lock dir. Safe to call twice. */ release(): void; } /** * Acquire the advisory lock at `dir`, waiting up to `waitMs`. Returns a * handle whose `release()` frees the lock, or `null` when the wait elapsed * with the lock still held by a live owner. */ export declare function acquireLock(options: AcquireLockOptions): Promise; /** * Run `fn` while holding the lock, releasing on both success and throw. * Returns `null` without running `fn` when the lock could not be acquired * within the wait bound. */ export declare function withLock(options: AcquireLockOptions, fn: () => Promise | T): Promise<{ acquired: boolean; result?: T; }>; //# sourceMappingURL=lock.d.ts.map