Skip to content

Latest commit

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

node-locker - full-featured client for locker lock server

Allows to lock common resources across servers with sub-second precision in node.js in async way.

Installation

Check out locker server page for server installation instructions.

npm install locker

Example

varLocker=require("locker"),locker=newLocker(4545,"127.0.0.1");locker.on("reset",function(){console.log("Reset happened (is server running?)");});locker.on("error",function(error){console.log("Catched error:",error);});// name wait max callbacklocker.locked("five",2000,3000,function(error,callback){if(error){// lock failedcallback(error);return;}// do whatever you want with your shared resourcecallback(undefined,{well: "done"});});

API

  • Requiring
varLocker=require("Locker");
  • New connection
varlocker=newLocker(port,host);
  • Locking resource
locker.locked(identifier,lock_wait_time,max_execution_time,callback)

callback signature:

function(error,next){}

In callback you will be exclusive owner of resource with name identifier if there is no error argument.

After doing exclusive stuff you should release lock by calling next callback.

Events

  • reset — connection was reset and all locks were gone.
  • error - error occurred on some of connection locks (timeout exceed for waiting or execution time)

About

Full-featured async client for locker lock server

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages