cross-process-lock
Version:
Cross-process file locking solution with lock-queue
24 lines (23 loc) • 950 B
TypeScript
import { LockOptions } from "./lock";
export type LockCallback<T> = () => Promise<T>;
/**
* Executes the callback with locking the given file before,
* and releasing it after the callback is executed.
*
* Generally, the callback/operation should target the file locked.
*
* @param file The path of the file to lock.
* @param callback The function to execute while the file is locked.
*/
export declare function withLock<T>(file: string, callback: LockCallback<T>): Promise<T>;
/**
* Executes the callback with locking the given file before,
* and releasing it after the callback is executed.
*
* Generally, the callback/operation should target the file locked.
*
* @param file The path of the file to lock.
* @param options The lock options/timeout.
* @param callback The function to execute while the file is locked.
*/
export declare function withLock<T>(file: string, options: LockOptions, callback: LockCallback<T>): Promise<T>;