Skip to content

Commit 1a478a4

Browse files
pimliesatazor
authored andcommitted
docs: add reject promise / throws on error message (#83)
* chore: add throws on error message * docs: remove false/unnecessary 'by throwing'
1 parent 3f905fd commit 1a478a4

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ As you see, the first two are a consequence of bad usage. Technically, it was po
6767

6868
### .lock(file, [options])
6969

70-
Tries to acquire a lock on `file`.
70+
Tries to acquire a lock on `file` or rejects the promise on error.
7171

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).
7373

7474
Available options:
7575

@@ -92,6 +92,11 @@ lockfile.lock('some/file')
9292
// Call the provided release function when you're done,
9393
// which will also return a promise
9494
return release();
95+
})
96+
.catch((e) => {
97+
// either lock could not be acquired
98+
// or releasing it failed
99+
console.error(e)
95100
});
96101

97102
// Alternatively, you may use lockfile('some/file') directly.
@@ -100,7 +105,7 @@ lockfile.lock('some/file')
100105

101106
### .unlock(file, [options])
102107

103-
Releases a previously acquired lock on `file`.
108+
Releases a previously acquired lock on `file` or rejects the promise on error.
104109

105110
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.
106111

@@ -125,7 +130,7 @@ lockfile.lock('some/file')
125130

126131
### .check(file, [options])
127132

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.
129134

130135
Available options:
131136

0 commit comments

Comments
 (0)