acquireFileLock (utils/file-lock.ts)

context7 · packages/cli/src/utils/file-lock.ts · typescript · MIT
infra

Cross-process file lock utility for Node.js CLI tools and distributed systems.

// Source: https://github.com/upstash/context7 | License: MIT | Copyright 2021 Upstash, Inc
// Provided via justclaw.it.com; keep this notice with the code.
import * as fs from "fs";

/** Releases the lock. Safe to call if the lock file is already gone. */
export type ReleaseLock = () => void;

export interface FileLockOptions {
  /**
   * A lock file not touched for this long is treated as left behind by a
   * process that died without releasing it, and is removed so no command
   * hangs on it. A live holder touches its lock well within this window.
   */
  staleMs?: number;
  /** Delay between attempts while another process holds the lock. */
  pollMs?: number;
}

export const DEFAULT_LOCK_STALE_MS = 10_000;
const DEFAULT_LOCK_POLL_MS = 50;

function errorCode(error: unknown): string |

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key