https://github.com/scull7/file-lock
A file based locking mechanism for node processes
https://github.com/scull7/file-lock
Last synced: 6 months ago
JSON representation
A file based locking mechanism for node processes
- Host: GitHub
- URL: https://github.com/scull7/file-lock
- Owner: scull7
- License: mit
- Created: 2015-10-12T23:51:46.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-10-13T21:55:45.000Z (almost 11 years ago)
- Last Synced: 2025-09-23T23:44:56.662Z (10 months ago)
- Language: CoffeeScript
- Size: 145 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/scull7/file-lock)
# file-lock
A file based locking mechanism for node processes
## Usage
```javascript
var Lock = require('file-lock');
var lockFilePath = '/tmp/my-lock'
Lock.obtain(lockFilePath, process.pid)
// All calls to lock functions return a Result( ok:, msg: )
// object.
.then(function(result) {
if (result.ok) {
// ... do stuff with synchronized resources.
} else {
throw new Error(result.msg);
}
return Lock.release(lockFilePath, process.pid);
})
.then(function(result) {
if (!result.ok) {
throw new Error(result.msg);
}
else {
// ... do non-synchronized stuff here.
}
});
```
### API
#### Lock.obtain :: String -> Int -> Promise Result (Bool, String)
#### Lock.release :: String -> Int -> Promise Result (Bool, String)
#### Lock.hasLock :: String -> Int -> Promise Result (Bool, String)