lock
lock asynchronous resources.
Last updated 10 years ago by dominictarr .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install lock 
SYNC missed versions from official npm registry.

lock

lock asynchronous resources.

Simple Example

var Lock = require('lock').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').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').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

Current Tags

  • 1.1.0                                ...           latest (7 years ago)

10 Versions

  • 1.1.0                                ...           7 years ago
  • 0.1.4                                ...           7 years ago
  • 0.1.3                                ...           8 years ago
  • 0.1.2                                ...           10 years ago
  • 0.1.0                                ...           11 years ago
  • 0.0.4                                ...           11 years ago
  • 0.0.3                                ...           12 years ago
  • 0.0.2                                ...           12 years ago
  • 0.0.1                                ...           12 years ago
  • 0.0.0                                ...           12 years ago
Maintainers (1)
Downloads
Total 10
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE