{"_id":"@atton16/cluster-lock","_rev":"1-6ba39d33b4ef69299ca36b3d38609153","name":"@atton16/cluster-lock","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@atton16/cluster-lock","version":"1.0.0","description":"A lock implementation for both single-thread and clustered Node.JS environment.","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"prebuild":"rimraf dist","build":"tsc","prebuild:watch":"rimraf dist","build:watch":"tsc -w","lint":"eslint \"{src,apps,libs,test}/**/*.ts\" --fix","test":"jest --detectOpenHandles --forceExit","test:watch":"jest --watch","test:cov":"jest --coverage","release":"standard-version"},"keywords":["lock","mutex","typescript"],"author":{"name":"Attawit Kittikrairit","email":"atton16@gmail.com","url":"https://attawit.me"},"license":"ISC","repository":{"type":"git","url":"git+https://github.com/atton16/cluster-lock.git"},"jest":{"moduleFileExtensions":["js","json","ts"],"rootDir":"src","testRegex":".spec.ts$","transform":{"^.+\\.(t|j)s$":"ts-jest"},"collectCoverageFrom":["**/*.(t|j)s"],"coverageDirectory":"../coverage","testEnvironment":"node"},"devDependencies":{"@types/jest":"^26.0.0","@typescript-eslint/eslint-plugin":"^3.3.0","@typescript-eslint/parser":"^3.3.0","eslint":"^7.2.0","eslint-config-prettier":"^6.11.0","eslint-plugin-import":"^2.21.2","jest":"^26.0.1","prettier":"^2.0.5","standard-version":"^9.0.0","ts-jest":"^26.1.0","ts-node":"^9.0.0","tsc-watch":"^4.2.8","tslint":"^6.1.2","typescript":"^3.9.5"},"gitHead":"7c7f56031be0b29544f38f4f4d5a697ff90b03db","bugs":{"url":"https://github.com/atton16/cluster-lock/issues"},"homepage":"https://github.com/atton16/cluster-lock#readme","_id":"@atton16/cluster-lock@1.0.0","_nodeVersion":"12.16.3","_npmVersion":"6.14.8","dist":{"integrity":"sha512-g959PRGX1FAe4e48vTtQrqxkLtEmc+6TYKt5TK28JaqsM0PVChjvMtIF7x8WjpgYr8Yr0JUygX03rqKnM3sVsw==","shasum":"5c2d1d49f084af2ce9f6ce02549ee455378ed603","tarball":"https://registry.npmjs.org/@atton16/cluster-lock/-/cluster-lock-1.0.0.tgz","fileCount":36,"unpackedSize":114232,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJflo7OCRA9TVsSAnZWagAAp7QP/1HGB6fGBQr3kldYiF5w\nOUc/3feK/1w0qPLnKFY5SXTP8np9nUfDGnz63+CE1tEWQukeD/1gHTpD9pAv\nnS01wDlSKGnZIh8pq/CEIOnUUXiEjNyRXr0+w8/fPsv9gzHN6eBe8IOGOfbG\n+QP7a/GVyduJQFWCpdO/uSm2JhGZmkDF/1WeO/6mbiML5Vg4OFhByJO9sKMy\njqBR7Sse3hQeZrNVDKibWm+5vGxMDVnXUndHm5RfnszUrmqmVg7hpZaZV7CP\nx2Qo3vHFjY7hCVNf8nF2sNRm1Kdk+9uNSd9JsG48nXvEg0Mz9z/LqWKeE746\njDdEO996LPB5sL50CTdDf/YTgCy1WICJ2pFHXjM1xe8nPQqQJxFFOTbBUiFx\nCEnHXaSEP4OoDEz/QeJfqg00lqZC+4uEog9OU25vAHsK9skeHltKOvBw+OCi\n4KCpi+RLBKJXPEK+QomOwwEoP5E+rr2VRztRYaSnn+wMLUE2haEL8sLYo1Qb\nDiTgNp7wzIpUwVikTkXtPYsBdUdgqI28ygSHs23GUK2bfuZGB1H8UWwvV9uj\nGYeqx3ruGyDYG52zfVz4h8NCgzbwlEgZujnljsICH8YBPskrqFAsAmX8TK1N\nIwoNO78xpquPXmjKV72YP80y714unebjf4EVWLOxflzkQVmaJm1LCRPDU+KD\njWxX\r\n=KLEG\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICRWgDDmJn/wnzbbBXZN2FgR9rO1b7FE+E4gouQVLHdTAiEAnnK1IUiJiAFhPaY2nxyWwSknSqXBuex1wXHIuGws7io="}]},"maintainers":[{"name":"atton16-org","email":"atton16@gmail.com"}],"_npmUser":{"name":"atton16-org","email":"atton16@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cluster-lock_1.0.0_1603702478497_0.5901490710616297"},"_hasShrinkwrap":false}},"time":{"created":"2020-10-26T08:54:38.253Z","1.0.0":"2020-10-26T08:54:38.664Z","modified":"2022-04-04T16:20:46.232Z"},"maintainers":[{"name":"atton16-org","email":"atton16@gmail.com"}],"description":"A lock implementation for both single-thread and clustered Node.JS environment.","homepage":"https://github.com/atton16/cluster-lock#readme","keywords":["lock","mutex","typescript"],"repository":{"type":"git","url":"git+https://github.com/atton16/cluster-lock.git"},"author":{"name":"Attawit Kittikrairit","email":"atton16@gmail.com","url":"https://attawit.me"},"bugs":{"url":"https://github.com/atton16/cluster-lock/issues"},"license":"ISC","readme":"# @atton16/cluster-lock\n\nA lock implementation for both single-thread and clustered Node.JS environment.\n\nThis is the simple lock implementation and might not be suitable for production application.\n\n## Installation\n\n```bash\nnpm install @atton16/cluster-lock\n```\n\n## Usage\n\n### Single Process\n\n```typescript\nimport { Lock } from '@atton16/cluster-lock';\n\nconst lock = new Lock('read-car');\n\nlock.acquire().then(() => {\n  console.log('I can now read car!');\n  lock.release();\n});\n\n```\n\n### Cluster\n\n```typescript\nimport cluter from 'cluster';\nimport { Lock } from '@atton16/cluster-lock';\n\nif (cluster.isMaster) {\n  const lock = new Lock('read-car'); // master lock instance is required\n  cluster.fork();  // worker 1\n  cluster.fork();  // worker 2\n  // NOTE: master process can also acquire lock\n  lock.acquire().then(() => {\n    console.log('I can now read car!');\n    lock.release();\n  });\n} else {\n  const lock = new Lock('read-car');\n\n  lock.acquire().then(() => {\n    console.log('I can now read car!');\n    lock.release();\n  });\n}\n\n```\n\n## Limitations\n\n1. Master lock instance is required in cluster mode.\n2. Same-name lock is supported in worker process only (which runs in cluster mode).\n\n## License\n\nISC License\n\nCopyright (c) 2020, Attawit Kittikrairit\n\nPermission to use, copy, modify, and/or distribute this software for any\npurpose with or without fee is hereby granted, provided that the above\ncopyright notice and this permission notice appear in all copies.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES\nWITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\nMERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR\nANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\nWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\nACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF\nOR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n","readmeFilename":"README.md"}