1 | export interface LockfileOptions {
|
2 | debug?: any;
|
3 | timeout?: number;
|
4 | retryInterval?: number;
|
5 | }
|
6 | export interface LockOptions {
|
7 | reason?: string;
|
8 | ifLocked: ({reason}: {
|
9 | reason?: string;
|
10 | }) => Promise<void> | void;
|
11 | timeout: number;
|
12 | retryInterval: number;
|
13 | }
|
14 | export default class Lockfile {
|
15 | base: string;
|
16 | timeout: number;
|
17 | retryInterval: number;
|
18 | stale: number;
|
19 | uuid: string;
|
20 | private fs;
|
21 | private _debug?;
|
22 | private _count;
|
23 | private updater?;
|
24 | |
25 |
|
26 |
|
27 | constructor(base: string, options?: LockfileOptions);
|
28 | readonly count: number;
|
29 | readonly dirPath: string;
|
30 | /**
|
31 | * creates a lock
|
32 | * same as add
|
33 | */
|
34 | lock(): Promise<void>;
|
35 | /**
|
36 | * creates a lock
|
37 | * same as add
|
38 | */
|
39 | lockSync(): void;
|
40 | /**
|
41 | * removes all lock counts
|
42 | */
|
43 | unlock(): Promise<void>;
|
44 | /**
|
45 | * removes all lock counts
|
46 | */
|
47 | unlockSync(): void;
|
48 | /**
|
49 | * adds 1 lock count
|
50 | */
|
51 | add(opts?: Partial<LockOptions>): Promise<void>;
|
52 | /**
|
53 | * adds 1 lock count
|
54 | */
|
55 | addSync(opts?: {
|
56 | reason?: string;
|
57 | }): void;
|
58 | /**
|
59 | * removes 1 lock count
|
60 | */
|
61 | remove(): Promise<void>;
|
62 | /**
|
63 | * removes 1 lock count
|
64 | */
|
65 | removeSync(): void;
|
66 | /**
|
67 | * check if this instance can get a lock
|
68 | * returns true if it already has a lock
|
69 | */
|
70 | check(): Promise<boolean>;
|
71 | /**
|
72 | * check if this instance can get a lock
|
73 | * returns true if it already has a lock
|
74 | */
|
75 | checkSync(): boolean;
|
76 | private readonly _infoPath;
|
77 | private fetchReason();
|
78 | private fetchReasonSync();
|
79 | private _saveReason(reason);
|
80 | private _saveReasonSync(reason);
|
81 | private fetchMtime();
|
82 | private fetchMtimeSync();
|
83 | private isStale(mtime?);
|
84 | private debug(msg, ...args);
|
85 | private _add(opts);
|
86 | private _lock(opts);
|
87 | private _lockSync({reason, retries}?);
|
88 | private _status(mtime);
|
89 | private startLocking();
|
90 | private _stopLocking();
|
91 | private _debugReport(action, reason?);
|
92 | }
|
93 | export interface RWLockfileOptions {
|
94 | debug?: any;
|
95 | file?: string;
|
96 | }
|