{"name":"mortice","version":"3.2.1","keywords":["async","await","cluster","lock","mutex","read-write"],"author":{"name":"Alex Potsides","email":"alex@achingbrain.net"},"license":"Apache-2.0 OR MIT","_id":"mortice@3.2.1","maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"homepage":"https://github.com/achingbrain/mortice#readme","bugs":{"url":"https://github.com/achingbrain/mortice/issues"},"dist":{"shasum":"e001f687885d0a28a6006e524b62212a7c4c3b64","tarball":"http://registry-npm.ywwl.com/mortice/download/mortice-3.2.1.tgz","fileCount":59,"integrity":"sha512-bsKOeA7lzmQKCMi3HReiG9HFoL/dRYTw9IoKwlcLM1yfzqTAsPHe63seSynZuI5//Av5IQGQyG+FyLYTWMfQog==","signatures":[{"sig":"MEUCIBYzs22wTGf+x1biQqdDQiflJV/3Ihs1gIZ5apyZZOVFAiEAjkyXKxiGncyD4dK56FkrzZbv+gA0kt4lBiJX1UD8Fw8=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/mortice@3.2.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":343381,"size":71445,"noattachment":false,"key":"/mortice/-/mortice-3.2.1.tgz"},"type":"module","types":"./dist/src/index.d.ts","browser":{"node:cluster":false,"./src/node.js":"./src/browser.js","./dist/src/node.js":"./dist/src/browser.js","node:worker_threads":false,"./test/fixtures/worker-post-message.js":"./test/fixtures/worker-post-message.browser.js"},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./dist/src/index.js"}},"gitHead":"6a8ef14bcb3c099a6f1e452e42a0250f276cae99","release":{"plugins":[["@semantic-release/commit-analyzer",{"preset":"conventionalcommits","releaseRules":[{"release":"major","breaking":true},{"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",{"assets":["CHANGELOG.md","package.json"]}]],"branches":["main"]},"scripts":{"docs":"aegir docs","lint":"aegir lint","test":"aegir test -t node -t browser","build":"aegir build && node esbuild.js","clean":"aegir clean","release":"aegir release","dep-check":"aegir dep-check -i esbuild","doc-check":"aegir doc-check","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"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"repository":{"url":"git+https://github.com/achingbrain/mortice.git","type":"git"},"_npmVersion":"10.9.2","description":"Isomorphic read/write lock that works in single processes, node clusters and web workers","directories":{},"_nodeVersion":"22.15.0","dependencies":{"it-queue":"^1.1.0","main-event":"^1.0.0","abort-error":"^1.0.0"},"publishConfig":{"access":"public","provenance":true},"_hasShrinkwrap":false,"devDependencies":{"aegir":"^47.0.15","delay":"^6.0.0","execa":"^9.5.3","esbuild":"^0.25.4","wherearewe":"^2.0.1","observable-webworkers":"^2.0.1"},"_npmOperationalInternal":{"tmp":"tmp/mortice_3.2.1_1748884754995_0.19829579586134316","host":"s3://npm-registry-packages-npm-production"},"readme":"# mortice\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<!--\n\n!IMPORTANT!\n\nEverything in this README between \"# About\" and \"# Install\" is automatically\ngenerated and will be overwritten the next time the doc generator is run.\n\nTo make changes to this section, please update the @packageDocumentation section\nof src/index.js or src/index.ts\n\nTo experiment with formatting, please run \"npm run docs\" from the root of this\nrepo and examine the changes made.\n\n-->\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## Example\n\n```ts\nimport mortice from 'mortice'\nimport delay from 'delay'\n\n// the lock name & options objects are both optional\nconst mutex = mortice()\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## Clean up\n\nMutexes are stored globally reference by name, this is so you can obtain the\nsame lock from different contexts, including workers.\n\nWhen a mutex is no longer required, the `.finalize` function should be called\nto remove any internal references to it.\n\n```ts\nimport mortice from 'mortice'\n\nconst mutex = mortice()\n\n// ...some time later\n\nmutex.finalize()\n```\n\n## Auto clean up\n\nIf your app generates a lot of short-lived mutexes and you want to clean them\nup after the last lock has been released, pass the `autoFinalize` option to\nmortice in the owning context:\n\n```ts\nimport mortice from 'mortice'\n\nconst mutex = mortice({\n  autoFinalize: true\n})\n\nconst release = await mutex.readLock()\n// ...some time later\n\nrelease()\n\n// mutex will be freed soon after\n```\n\n## React native support\n\nThis module should run on react native but it only supports single-process\nconcurrency as it's not clear to the author (disclaimer - not a react native\ndev) what the officially supported process concurrency model is.\n\nPlease open an issue if this is a feature you would like to see added.\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 its 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](https://github.com/achingbrain/mortice/LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](https://github.com/achingbrain/mortice/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":1748884755187,"_cnpm_publish_time":1748884755187,"dist-tags":{"latest":"3.3.1"}}