3 A very polite lock file utility, which endeavors to not litter, and to
4 wait patiently for others.
9 var lockFile = require('lockfile')
11 // opts is optional, and defaults to {}
12 lockFile.lock('some-file.lock', opts, function (er) {
13 // if the er happens, then it failed to acquire a lock.
14 // if there was not an error, then the file was created,
15 // and won't be deleted until we unlock it.
17 // do my stuff, free of interruptions
18 // then, some time later, do:
19 lockFile.unlock('some-file.lock', function (er) {
20 // er means that an error happened, and is probably bad.
27 Sync methods return the value/throw the error, others don't. Standard
30 All known locks are removed when the process exits. Of course, it's
31 possible for certain types of failures to cause this to fail, but a best
32 effort is made to not be a litterbug.
34 ### lockFile.lock(path, [opts], cb)
36 Acquire a file lock on the specified path
38 ### lockFile.lockSync(path, [opts])
40 Acquire a file lock on the specified path
42 ### lockFile.unlock(path, cb)
44 Close and unlink the lockfile.
46 ### lockFile.unlockSync(path)
48 Close and unlink the lockfile.
50 ### lockFile.check(path, [opts], cb)
52 Check if the lockfile is locked and not stale.
54 Callback is called with `cb(error, isLocked)`.
56 ### lockFile.checkSync(path, [opts])
58 Check if the lockfile is locked and not stale.
66 A number of milliseconds to wait for locks to expire before giving up.
67 Only used by lockFile.lock. Poll for `opts.wait` ms. If the lock is
68 not cleared by the time the wait expires, then it returns with the
73 When using `opts.wait`, this is the period in ms in which it polls to
74 check if the lock has expired. Defaults to `100`.
78 A number of milliseconds before locks are considered to have expired.
82 Used by lock and lockSync. Retry `n` number of times before giving up.
86 Used by lock. Wait `n` milliseconds before retrying.