{"name":"mortice","version":"1.0.1","description":"Isomorphic read/write lock that works in single processes, node clusters and web workers","main":"lib/index.js","scripts":{"test":"ava","lint":"standard"},"keywords":["read-write","cluster","mutex","lock","await","async"],"author":{"name":"Alex Potsides","email":"alex@achingbrain.net"},"license":"ISC","repository":{"type":"git","url":"git+https://github.com/achingbrain/mortice.git"},"bugs":{"url":"https://github.com/achingbrain/mortice/issues"},"homepage":"https://github.com/achingbrain/mortice","devDependencies":{"ava":"^0.25.0","browserify":"^16.2.2","execa":"^0.10.0","run-headless":"^2.0.1","standard":"^11.0.1","webworkify":"^1.5.0"},"ava":{"files":["test/*.test.js"],"concurrency":1},"dependencies":{"observable-webworkers":"^1.0.0","p-queue":"^2.4.2","promise-timeout":"^1.3.0","shortid":"^2.2.8"},"gitHead":"9ed1c776e9b6d6be8fd958631798d4e34d6ca0b4","_id":"mortice@1.0.1","_npmVersion":"5.6.0","_nodeVersion":"8.9.4","_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"dist":{"integrity":"sha512-jH3RNaWhAJOfMk4LLmPVAJCm/kNz0sUHrGxQbcSNVRQSba1fXylwGMLVV5uHehekEVzdTQdnFJ0ZCMUqO+N2vw==","shasum":"035a8fccf0fe45f1b9f20e8eacd7cd4ce82d8e71","tarball":"http://registry-npm.ywwl.com/mortice/download/mortice-1.0.1.tgz","fileCount":16,"unpackedSize":18381,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbDqnWCRA9TVsSAnZWagAAGQUQAIiCFdFJ7+RrlILyg3OW\nhidwUGYdMsHiZAXRaI9zKp1rj2ImTBhp9HBcAMLOM6Sf1NVUp1kUL1mQF9bG\nQ7ha/Fz4SalVwwhCHMFqcnOjwnhjGt8jChJXTNAiPJaMCa2WHlrjOTx1jhGL\nwwfmLhn8RBHTpMQTiTConxDijFic98Hq4r9HG+bz9IroAF8Vb8q/q96lp3cL\nms7UccoKo3oj3eLzTFOsjcV4yv6JO8R/JffU2dY41LxRbdhUPvjNQfw/IrK0\nmahV/MviW+dFwPCpBx45cD7wq4LXGubOUnVBPVQ4tVlMOXB1Gh/YEa7vMbck\nxTsyNHV6aLoOeIH6Brzm86WS3erH/pqVeQYlK+g8DFp4v9T1QYrqEYXnbsNZ\nup6RQPqXetYk8hhJgW8wa4NpQYIyHWDz4uHU78x2QfDD6r7y35EAFxp9Fgfl\nWnUENWK06+/IbEko7D3V2gokPRCEHJ2bNKXfFKri6joowHGKx0bq83GD/IiF\nqK//sfQrA6N3YUfw+amNUF1z0sezLLr0Rr3agqvfcQpXZCJiO5cNHWGzJa6N\nyR7s921LZ7UcphGu+8Ti2Gkd9I4Of4Xq9wPNjSF/zhor9fAh9f8K1nNWoQWd\n07Y6Cfb/UVy3LpdO5StkwyHlVzV9HRZKu4DfN+5uRuV9T3ieXU/ZPLTcGzkD\nwWQk\r\n=0BsP\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQComKJwBOOVTKZKuhHgW3zG5vmD8xBrezBJRFWqjM22wQIgHm3i2K5cmxqpYsXRH5WCqBkdCUiv/3U0THBaPehVqHA="}],"size":4170,"noattachment":false,"key":"/mortice/-/mortice-1.0.1.tgz"},"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mortice_1.0.1_1527687636075_0.9084618873240549"},"_hasShrinkwrap":false,"readme":"# mortice <!-- omit in toc -->\n\n[![codecov](https://img.shields.io/codecov/c/github/achingbrain/mortice.svg?style=flat-square)](https://codecov.io/gh/achingbrain/mortice)\n[![CI](https://img.shields.io/github/actions/workflow/status/achingbrain/mortice/js-test-and-release.yml?branch=main\\&style=flat-square)](https://github.com/achingbrain/mortice/actions/workflows/js-test-and-release.yml?query=branch%3Amain)\n\n> Isomorphic read/write lock that works in single processes, node clusters and web workers\n\n# About\n\n- Reads occur concurrently\n- Writes occur one at a time\n- No reads occur while a write operation is in progress\n- Locks can be created with different names\n- Reads/writes can time out\n\n## Usage\n\n```javascript\nimport mortice from 'mortice'\nimport delay from 'delay'\n\n// the lock name & options objects are both optional\nconst mutex = mortice('my-lock', {\n\n  // how long before write locks time out (default: 24 hours)\n  timeout: 30000,\n\n   // control how many read operations are executed concurrently (default: Infinity)\n  concurrency: 5,\n\n  // by default the the lock will be held on the main thread, set this to true if the\n  // a lock should reside on each worker (default: false)\n  singleProcess: false\n})\n\nPromise.all([\n  (async () => {\n    const release = await mutex.readLock()\n\n    try {\n      console.info('read 1')\n    } finally {\n      release()\n    }\n  })(),\n  (async () => {\n    const release = await mutex.readLock()\n\n    try {\n      console.info('read 2')\n    } finally {\n      release()\n    }\n  })(),\n  (async () => {\n    const release = await mutex.writeLock()\n\n    try {\n      await delay(1000)\n\n      console.info('write 1')\n    } finally {\n      release()\n    }\n  })(),\n  (async () => {\n    const release = await mutex.readLock()\n\n    try {\n      console.info('read 3')\n    } finally {\n      release()\n    }\n  })()\n])\n```\n\n```\nread 1\nread 2\n<small pause>\nwrite 1\nread 3\n```\n\n## Browser\n\nBecause there's no global way to evesdrop on messages sent by Web Workers, please pass all created Web Workers to the [`observable-webworkers`](https://npmjs.org/package/observable-webworkers) module:\n\n```javascript\n// main.js\nimport mortice from 'mortice'\nimport observe from 'observable-webworkers'\n\n// create our lock on the main thread, it will be held here\nconst mutex = mortice()\n\nconst worker = new Worker('worker.js')\n\nobserve(worker)\n```\n\n```javascript\n// worker.js\nimport mortice from 'mortice'\nimport delay from 'delay'\n\nconst mutex = mortice()\n\nlet release = await mutex.readLock()\n// read something\nrelease()\n\nrelease = await mutex.writeLock()\n// write something\nrelease()\n```\n\n# Install\n\n```console\n$ npm i mortice\n```\n\n## Browser `<script>` tag\n\nLoading this module through a script tag will make it's exports available as `Mortice` in the global namespace.\n\n```html\n<script src=\"https://unpkg.com/mortice/dist/index.min.js\"></script>\n```\n\n# API Docs\n\n- <https://achingbrain.github.io/mortice>\n\n# License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n# Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n","publish_time":1527687637302,"_cnpm_publish_time":1527687637302,"dist-tags":{"latest":"3.3.1"}}