You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+9-4Lines changed: 9 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -67,9 +67,9 @@ As you see, the first two are a consequence of bad usage. Technically, it was po
67
67
68
68
### .lock(file, [options])
69
69
70
-
Tries to acquire a lock on `file`.
70
+
Tries to acquire a lock on `file` or rejects the promise on error.
71
71
72
-
If the lock succeeds, a `release` function is provided that should be called when you want to release the lock.
72
+
If the lock succeeds, a `release` function is provided that should be called when you want to release the lock. The `release` function also rejects the promise on error (e.g. when the lock was already compromised).
73
73
74
74
Available options:
75
75
@@ -92,6 +92,11 @@ lockfile.lock('some/file')
92
92
// Call the provided release function when you're done,
93
93
// which will also return a promise
94
94
returnrelease();
95
+
})
96
+
.catch((e) => {
97
+
// either lock could not be acquired
98
+
// or releasing it failed
99
+
console.error(e)
95
100
});
96
101
97
102
// Alternatively, you may use lockfile('some/file') directly.
@@ -100,7 +105,7 @@ lockfile.lock('some/file')
100
105
101
106
### .unlock(file, [options])
102
107
103
-
Releases a previously acquired lock on `file`.
108
+
Releases a previously acquired lock on `file` or rejects the promise on error.
104
109
105
110
Whenever possible you should use the `release` function instead (as exemplified above). Still there are cases in which its hard to keep a reference to it around code. In those cases `unlock()` might be handy.
106
111
@@ -125,7 +130,7 @@ lockfile.lock('some/file')
125
130
126
131
### .check(file, [options])
127
132
128
-
Check if the file is locked and its lockfile is not stale.
133
+
Check if the file is locked and its lockfile is not stale, rejects the promise on error.
0 commit comments