@shockpkg/core
Version:
shockpkg core
78 lines (77 loc) • 1.83 kB
TypeScript
import { Dispatcher } from './dispatcher';
/**
* Lock constructor.
*
* @param path The path to lock.
*/
export declare class Lock extends Object {
/**
* Duration at which the lock is considered stale in milliseconds.
* Minimum value of 2000.
*/
stale: number;
/**
* Update interval in milliseconds.
*/
update: number;
/**
* The number of retries to attempt to aquire the lock.
*/
retries: number;
/**
* Resolve symlinks using realpath.
*/
realpath: boolean;
/**
* Compromised lock events.
*/
readonly eventCompromised: Dispatcher<Error>;
/**
* Lock has been compromised since aquire.
*/
protected _compromised: boolean;
/**
* The path to lock.
*/
protected _path: string;
/**
* The lock release function.
*/
protected _release: (() => Promise<void>) | null;
constructor(path: string);
/**
* The path to lock.
*
* @returns The path.
*/
readonly path: string;
/**
* Boolean for if lock is held.
* The lock could be compromised and not yet detected however.
*
* @returns Is held.
*/
readonly held: boolean;
/**
* Boolean for if the lock hase been compromised since aquire.
* The lock could be compromised and not yet detected however.
*
* @returns Is compromised.
*/
readonly compromised: boolean;
/**
* Check if path is already locked by any instance including this one.
* Does not verify the lock file belongs to this instance.
*
* @returns True if locked, false if not.
*/
check(): Promise<boolean>;
/**
* Aquire lock or fail.
*/
aquire(): Promise<void>;
/**
* Release lock or fail.
*/
release(): Promise<void>;
}