{"name":"mortice","version":"3.0.1","description":"Isomorphic read/write lock that works in single processes, node clusters and web workers","author":{"name":"Alex Potsides","email":"alex@achingbrain.net"},"license":"Apache-2.0 OR MIT","homepage":"https://github.com/achingbrain/mortice#readme","repository":{"type":"git","url":"git+https://github.com/achingbrain/mortice.git"},"bugs":{"url":"https://github.com/achingbrain/mortice/issues"},"keywords":["async","await","cluster","lock","mutex","read-write"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","exports":{".":{"types":"./dist/src/index.d.ts","import":"./dist/src/index.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"release":{"branches":["master"],"plugins":[["@semantic-release/commit-analyzer",{"preset":"conventionalcommits","releaseRules":[{"breaking":true,"release":"major"},{"revert":true,"release":"patch"},{"type":"feat","release":"minor"},{"type":"fix","release":"patch"},{"type":"docs","release":"patch"},{"type":"test","release":"patch"},{"type":"deps","release":"patch"},{"scope":"no-release","release":false}]}],["@semantic-release/release-notes-generator",{"preset":"conventionalcommits","presetConfig":{"types":[{"type":"feat","section":"Features"},{"type":"fix","section":"Bug Fixes"},{"type":"chore","section":"Trivial Changes"},{"type":"docs","section":"Documentation"},{"type":"deps","section":"Dependencies"},{"type":"test","section":"Tests"}]}}],"@semantic-release/changelog","@semantic-release/npm","@semantic-release/github","@semantic-release/git"]},"scripts":{"clean":"aegir clean","lint":"aegir lint","test":"aegir test -t node -t browser","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:firefox":"aegir test -t browser -- --browser firefox","test:electron-main":"aegir test -f dist/test/node.js -t electron-main","build":"aegir build && node esbuild.js","release":"aegir release"},"dependencies":{"nanoid":"^4.0.0","observable-webworkers":"^2.0.1","p-queue":"^7.2.0","p-timeout":"^6.0.0"},"devDependencies":{"aegir":"^37.5.1","delay":"^5.0.0","esbuild":"^0.15.5","execa":"^6.0.0","wherearewe":"^2.0.1"},"browser":{"cluster":false,"./dist/src/node.js":"./dist/src/browser.js","./src/node.js":"./src/browser.js"},"gitHead":"0eab826e744c8bc23ac65d17ac3a44e5f4694a3d","_id":"mortice@3.0.1","_nodeVersion":"16.16.0","_npmVersion":"8.17.0","dist":{"integrity":"sha512-eyDUsl1nCR9+JtNksKnaESLP9MgAXCA4w1LTtsmOSQNsThnv++f36rrBu5fC/fdGIwTJZmbiaR/QewptH93pYA==","shasum":"27c1943b1841502c7b27a9c8fea789f87c124515","tarball":"http://registry-npm.ywwl.com/mortice/download/mortice-3.0.1.tgz","fileCount":23,"unpackedSize":44101,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIF9YjY+5TFGorP3iw8g8i4UMCRhm9L/fQiw3nyaaeqtwAiAkVPYQX/uMH261zXyPWPlAt6HLAK2nH+cWV8CRVCBLgQ=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJi/KpJACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqoEg//Uw7dzis7ceoK8bonGTtZEx4IsCZa5vJSFrd9DaEPGAygSwpe\r\nvTGoe6J4fbEmnmIf7+g8fWodoZ9RUkRoIpEErzIbGdBZraJvsJEwUu9mZVs8\r\nD2An1v9/MQWNackvSwr4WJvTqf/W3ld3Hti0QWgbjNS7Dto/w4UCaDZg7mOx\r\nZXeohHtaGvs8trHEsjcpYX5nJQZTw8VGFWWt6SkhKhs8xP1lYf5HY6VrWsH6\r\nmTdjAIn7mjgs/FGKJX6BgRb+X8ZvjoQAiGPbHR59b/oF+1E8+7J0kva8yN/I\r\nUHtRFNwIe5kphh2ZsCtRm2Dj6Vo4IZraP3bpU80Rj3fAwtkMFh+Y7I/XUR/j\r\nIqJYFEV3v0LZSsNUWKLvCGV8Lu+KIH0EEs24lGfm0AzGFKwIyepnR33WbZjW\r\n7MEnSfFGym9vtSh0ru1YpgmhHQJhsAfzSVfCzKpDjhxER60i1xzdeCOrIahP\r\nhxhMFBDvYdUbdCxOICVJZCPoT/YBdM8AceClGOs8nEUCy/6lgExplZrKmD/k\r\nri6SbdVPY7Y75PMRWSU6sFotbV4xEPSoREF/NA1iFweCn2li+vRHHnmMb4+0\r\njmn3KdRC4yvduuoR3oKOOx8GScSMiheJJaPWJ113EWnkcuc0kvj/j9uZq4Qy\r\nVvkp+zsMGrmApk3oE4zcAmPiBVH0Tl/yd4Y=\r\n=Zvar\r\n-----END PGP SIGNATURE-----\r\n","size":9603,"noattachment":false,"key":"/mortice/-/mortice-3.0.1.tgz"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mortice_3.0.1_1660725833595_0.14212391062847063"},"_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":1660725833731,"_cnpm_publish_time":1660725833731,"dist-tags":{"latest":"3.3.1"}}