Skip to content

Commit

Permalink
docs: add reject promise / throws on error message (#83)
Browse files Browse the repository at this point in the history
* chore: add throws on error message

* docs: remove false/unnecessary 'by throwing'
  • Loading branch information
pimlie authored and satazor committed Mar 23, 2019
1 parent 3f905fd commit 1a478a4
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions README.md
Expand Up @@ -67,9 +67,9 @@ As you see, the first two are a consequence of bad usage. Technically, it was po

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

Tries to acquire a lock on `file`.
Tries to acquire a lock on `file` or rejects the promise on error.

If the lock succeeds, a `release` function is provided that should be called when you want to release the lock.
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).

Available options:

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

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

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

Releases a previously acquired lock on `file`.
Releases a previously acquired lock on `file` or rejects the promise on error.

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.

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

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

Check if the file is locked and its lockfile is not stale.
Check if the file is locked and its lockfile is not stale, rejects the promise on error.

Available options:

Expand Down

0 comments on commit 1a478a4

Please sign in to comment.