Skip to content

scull7/file-lock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

file-lock

A file based locking mechanism for node processes

Usage

var Lock  = require('file-lock');
var lockFilePath  = '/tmp/my-lock'

Lock.obtain(lockFilePath, process.pid)

// All calls to lock functions return a Result( ok:<bool>, msg:<string> )
// 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)

About

A file based locking mechanism for node processes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published