withFileLock (utils/file-lock.ts)

mcp-compress-router · src/utils/file-lock.ts · typescript · MIT
infra

Provides an async file lock utility that safely acquires, renews, and releases exclusive locks across processes.

// Source: https://github.com/ameshkov/mcp-compress-router | License: MIT | Copyright 2026 Andrey Meshkov
// Provided via justclaw.it.com; keep this notice with the code.
import * as fs from 'node:fs/promises';
import { randomUUID } from 'node:crypto';

/**
 * Options controlling how {@link withFileLock} waits for and reclaims a
 * lock file.
 */
export interface FileLockOptions {
  /**
   * Maximum time (ms) to wait for the lock before failing. Defaults to
   * 15000.
   */
  timeoutMs?: number;
  /**
   * Age (ms) after which a lock file whose mtime has not been renewed is
   * considered abandoned and may be reclaimed. The holder renews the
   * mtime while its task runs, so a live holder is never reclaimed.
   * Defaults to 10000.
   */
  staleMs?: number;
  /**
   * Base delay (ms) be

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

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

Get a free API key