lock asynchronous resources
JavaScript
Switch branches/tags
Nothing to show
Latest commit 94284d2 Jul 13, 2017 @octatone octatone committed on GitHub 0.1.4 (#13)
Permalink
Failed to load latest commit information.
test test for optional done Dec 4, 2013
.gitignore initial Feb 3, 2013
LICENSE initial Feb 3, 2013
README.md
index.d.ts Add TypeScript module type definition (#12) Jul 13, 2017
index.js fallback to setTimeout if setImmediate is not available Aug 19, 2016
package.json 0.1.4 (#13) Jul 13, 2017

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