{"name":"mutexify","version":"1.2.0","description":"mutex lock for javascript","main":"index.js","dependencies":{},"devDependencies":{"tape":"^3.0.2"},"scripts":{"test":"tape test.js"},"repository":{"type":"git","url":"git+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":"9e157b322806fdd8c52b0ecefdf3d8ad741b0575","_id":"mutexify@1.2.0","_npmVersion":"5.3.0","_nodeVersion":"8.2.1","_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"dist":{"integrity":"sha512-oprzxd2zhfrJqEuB98qc1dRMMonClBQ57UPDjnbcrah4orEMTq1jq3+AcdFe5ePzdbJXI7zmdhfftIdMnhYFoQ==","shasum":"45597975a2b035f56dcf61ff15cc8d73c28e7639","tarball":"http://registry-npm.ywwl.com/mutexify/download/mutexify-1.2.0.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIC8USYv8Hp61ZRHijXhYa84y+S6qYqJaasBnDfCYPDAvAiArf9LR5RI3eSFvnQkeSlvzKo+q8wV1W3JGMjxXiy02JA=="}],"size":2299,"noattachment":false,"key":"/mutexify/-/mutexify-1.2.0.tgz"},"maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mutexify-1.2.0.tgz_1502347301681_0.04014034825377166"},"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":1502347301749,"_cnpm_publish_time":1502347301749,"dist-tags":{"latest":"1.4.0"}}