{"name":"mutexify","version":"1.0.1","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":"fb259d8981abc4f56cf7f81e10ef3259e4bafc79","_id":"mutexify@1.0.1","_shasum":"9880206795d89e75efc1bcb4b4f52ebbd796e5e7","_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":"9880206795d89e75efc1bcb4b4f52ebbd796e5e7","tarball":"http://registry-npm.ywwl.com/mutexify/download/mutexify-1.0.1.tgz","integrity":"sha512-DFEDJKo0RaLSxN47hu5vqfDSDKmxGtp0xWNvueT3FX84s6Cm7VqOPJVxCnsAHUT3Lxa3kGAeqDtAHduDdYkKjQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCxRzYEXV8uCB74HPpyYnEa0tey6uVxY0Y1+8gKWy2jfQIgWfTwa9NQsoh8vTrcWg3toJu5zojeKouBZk0ROOg7P9I="}],"size":2037,"noattachment":false,"key":"/mutexify/-/mutexify-1.0.1.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":1415646310087,"_cnpm_publish_time":1415646310087,"dist-tags":{"latest":"1.4.0"}}