{"name":"mutexify","version":"1.0.0","description":"mutex lock for javascript","main":"index.js","dependencies":{},"devDependencies":{"tape":"^3.0.2"},"scripts":{"test":"tape test.js"},"repository":{"type":"git","url":"https://github.com/mafintosh/mutexify.git"},"author":{"name":"Mathias Buus","url":"@mafintosh"},"license":"MIT","bugs":{"url":"https://github.com/mafintosh/mutexify/issues"},"keywords":["mutex","lock"],"homepage":"https://github.com/mafintosh/mutexify","gitHead":"2496a3bb4154831760e6357567b8453882ae0808","_id":"mutexify@1.0.0","_shasum":"dfd0f58232bb977462d0db278061f8202b93b595","_from":".","_npmVersion":"2.1.7","_nodeVersion":"0.10.33","_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"}],"dist":{"shasum":"dfd0f58232bb977462d0db278061f8202b93b595","tarball":"http://registry-npm.ywwl.com/mutexify/download/mutexify-1.0.0.tgz","integrity":"sha512-tbbjLzUl68lXpiGcNnk8ALa9VQIZLNsRrKSTDxtW3VUm8/+YQU7IiYGwcI5bzKngexn3wNSO1NuYB56aodcogg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHHkHXKOEHKMnfFb91KUELyznj3q+nciaVmfkdIBvR2rAiEAsbbmdKOjHDddyayYzk0uh7QK4MzEDM+AuUyq8GzCdJ8="}],"size":1910,"noattachment":false,"key":"/mutexify/-/mutexify-1.0.0.tgz"},"directories":{},"readme":"# mutexify\n\nBike shed mutex lock implementation in node.js\n\n```\nnpm install mutexify\n```\n\n[![build status](http://img.shields.io/travis/mafintosh/mutexify.svg?style=flat)](http://travis-ci.org/mafintosh/mutexify)\n\nHasn't this been done before? Yes, but the specific semantics of this made some of my code simpler.\n\n## Usage\n\n\n``` js\nvar mutexify = require('mutexify')\nvar lock = mutexify()\n\nlock(function(release) {\n  console.log('i am now locked')\n  setTimeout(function() {\n    release()\n  }, 1000)\n})\n\nlock(function(release) {\n  console.log('1 second later')\n  release()\n})\n```\n\nA common pattern is to call a callback after you release the lock.\nTo do this in a one-liner pass the callback and the value to `release(cb, err, value)`\n\n``` js\nvar write = function(data, cb) {\n  lock(function(release) {\n    fs.writeFile('locked-file.txt', data, release.bind(null, cb))\n  })\n}\n```\n\n`mutexify` guarantees that the order that a mutex was requested in is the order that access will be given.\n\nYou can read the lock's current state on the `lock.locked` property.\n\n### Usage with promises\n\n`mutexify` provides a Promise-based alternative.\n\n```js\nconst mutexify = require('mutexify/promise')\n\n;(async () => {\n  var lock = mutexify()\n\n  var release = await lock()\n  console.log('i am now locked')\n  setTimeout(function () {\n    release()\n  }, 1000)\n\n  release = await lock()\n  console.log('1 second later')\n  release()\n})()\n```\n\n## License\n\nMIT\n","publish_time":1415645858639,"_cnpm_publish_time":1415645858639,"dist-tags":{"latest":"1.4.0"}}