{"_id":"@chalker/queue","_rev":"2-ef746353cd95a4b8d706ed12959bd6a3","name":"@chalker/queue","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@chalker/queue","version":"1.0.0","keywords":["queue","mutex","lock"],"license":"MIT","_id":"@chalker/queue@1.0.0","maintainers":[{"name":"chalker","email":"chalkerx@gmail.com"}],"homepage":"https://github.com/ChALkeR/queue","bugs":{"url":"https://github.com/ChALkeR/queue/issues"},"dist":{"shasum":"752ebcce15d060df8e8c5066e45971655c0c95a2","tarball":"https://registry.npmjs.org/@chalker/queue/-/queue-1.0.0.tgz","fileCount":4,"integrity":"sha512-WIIEU7B3vO1JQelTuipH5/W/HfirpDUPNzQaCY4IsSR6WEF1lKuEPon7EjQQ1iyXawU6hm0QcxxBcmKdwL1CDg==","signatures":[{"sig":"MEUCIQDXJKG1cLL45fBZhVbFswd/t4KAwPgkgy1mqZg8yLhprQIgFMVzLew6J149TxASEp9QiisQ5W+pzUn9u0fItb6Tm3U=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":3938},"main":"./index.mjs","type":"module","gitHead":"3e9f0ea83f23b21c40afa1ebe0300b045127852b","_npmUser":{"name":"chalker","email":"chalkerx@gmail.com"},"repository":{"url":"git+https://github.com/ChALkeR/queue.git","type":"git"},"_npmVersion":"10.8.1","description":"A trivial queue / mutex lock implementation","directories":{},"_nodeVersion":"22.3.0","dependencies":{},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/queue_1.0.0_1718448341135_0.6316750415669885","host":"s3://npm-registry-packages"}},"1.0.1":{"name":"@chalker/queue","version":"1.0.1","description":"A trivial queue / mutex lock implementation","license":"MIT","type":"module","main":"./index.mjs","repository":{"type":"git","url":"git+https://github.com/ChALkeR/queue.git"},"bugs":{"url":"https://github.com/ChALkeR/queue/issues"},"homepage":"https://github.com/ChALkeR/queue","publishConfig":{"access":"public"},"dependencies":{},"keywords":["queue","mutex","lock"],"_id":"@chalker/queue@1.0.1","gitHead":"66f0880437df8ba3d7a6fd775594edc93189d268","_nodeVersion":"22.15.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-j8iu20wUUgTnW3V5r5UKuUab3hT2odAGBlB7G2qxu+BFw9GFO8se2B/Su9SAtLj/CcKZzMFrwHREIG9hDIFo2Q==","shasum":"8cafdfd206c42889598db37a8530c341134256ee","tarball":"https://registry.npmjs.org/@chalker/queue/-/queue-1.0.1.tgz","fileCount":4,"unpackedSize":3844,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCNrV4Tf5v2d/Ah9i4XoMg43KxFLgUwZEoVihqG1kncEgIhAOJSNrbzG4idRa+WsXDfMr7u5Oe4xyLeNgHdrDI8kRf/"}]},"_npmUser":{"name":"chalker","email":"chalkerx@gmail.com"},"directories":{},"maintainers":[{"name":"chalker","email":"chalkerx@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/queue_1.0.1_1746949909724_0.6238366415851766"},"_hasShrinkwrap":false}},"time":{"created":"2024-06-15T10:45:40.980Z","modified":"2025-05-11T07:51:50.109Z","1.0.0":"2024-06-15T10:45:41.304Z","1.0.1":"2025-05-11T07:51:49.926Z"},"bugs":{"url":"https://github.com/ChALkeR/queue/issues"},"license":"MIT","homepage":"https://github.com/ChALkeR/queue","keywords":["queue","mutex","lock"],"repository":{"type":"git","url":"git+https://github.com/ChALkeR/queue.git"},"description":"A trivial queue / mutex lock implementation","maintainers":[{"name":"chalker","email":"chalkerx@gmail.com"}],"readme":"# @chalker/queue\n\nA trivial Queue / Lock implementation that I used in my personal projects.\n\nExample: https://github.com/nodejs/Gzemnid/blob/main/src/queue.js\n\n## Queue\n\nUsage:\n\n```js\nimport { Queue } from '@chalker/queue'\n\nconst queue = new Queue(10) // concurrency\n\nasync function run() {\n  await queue.claim()\n  // do async stuff with controlled maximum concurrency\n  queue.release()\n}\n```\n\n## Lock\n\n`new Lock()` is just an alias to `new Queue(1)`, which can be used \n\n```js\nimport { Queue } from '@chalker/queue'\n\nconst lock = new Lock()\n\nasync function run() {\n  await lock.claim()\n  // do async stuff with maximum concurrency = 1\n  lock.release()\n}\n```\n\n## Full example\n\n```js\nimport { Queue } from '@chalker/queue'\n\nconst queue = new Queue(3)\n\nlet concurrency = 0 // Just for testing purposes\nasync function run(x) {\n  await queue.claim()\n  console.log(`Start #${x}, concurrency: ${++concurrency}`)\n  await new Promise(resolve => setTimeout(resolve, 1))\n  console.log(`End #${x}, concurrency: ${concurrency--}`)\n  queue.release()\n}\n\nconst args = new Array(6).fill(0).map((_, i) => i + 1)\nawait Promise.all(args.map(run))\n```\n\nOutput:\n```\nStart #1, concurrency: 1\nStart #2, concurrency: 2\nStart #3, concurrency: 3\nEnd #1, concurrency: 3\nStart #4, concurrency: 3\nEnd #2, concurrency: 3\nStart #5, concurrency: 3\nEnd #3, concurrency: 3\nStart #6, concurrency: 3\nEnd #4, concurrency: 3\nEnd #5, concurrency: 2\nEnd #6, concurrency: 1\n```\n\n## License\n\n[MIT](./LICENSE)","readmeFilename":"README.md"}