Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
lock asynchronous resources
JavaScript
branch: master
Failed to load latest commit information.
test test for optional done
.gitignore initial
LICENSE initial
README.md docs for optional done
index.js setImmediate is now recommended especially in recursive environments.
package.json 0.1.2

README.md

lock

lock asynchronous resources.

Simple Example

var Lock = require('lock')
var lock = Lock()

lock('key', function (release) { //called when resource is available.

  //do an async operation, and wrap the callback with release.
  someAsyncOperation(args,..., release(function (err) {
    //'key' is now unlocked!
  })
})

Multiple Locks at Once.

var Lock = require('lock')
var lock = Lock()

lock(['A', 'B', 'C'], function (release) { //called, when ALL
                                           //resources are available.

  //do an async operation, and wrap the callback with release(cb)
  someAsyncOperation(args,..., release(function (err) {
    //A, B & C are now unlocked!
  })
})

Lock with optional callback.

var Lock = require('lock');
var lock = Lock();

lock('cache', function(release) { //called when no one is writing to cache
    //we do not care if this fails since its a cache so no callback needed
    fs.writeFile(fileCache, ... , release())
})

used in level-update

License

MIT

Something went wrong with that request. Please try again.