{"_id":"@async-cancellables/async-lock","_rev":"2-ed8d79c3402e51c6dfe4024e5c0f91c7","name":"@async-cancellables/async-lock","dist-tags":{"latest":"2.2.0"},"versions":{"2.0.0":{"name":"@async-cancellables/async-lock","version":"2.0.0","description":"Asynchronous lock pool with priorities and cancellation support","main":"index.js","type":"module","repository":{"type":"git","url":"git+https://github.com/vuwuv/async-cancellables.git","directory":"packages/async-lock"},"keywords":["async","cancellable","AsyncLock","cancellation","lock"],"author":{"name":"vuwuv"},"license":"MIT","bugs":{"url":"https://github.com/vuwuv/async-cancellables/issues"},"homepage":"https://github.com/vuwuv/async-cancellables#readme","peerDependencies":{"@async-cancellables/ct":"^2.0.0"},"engines":{"node":">=18.0.0"},"gitHead":"cca86a13c78c2c9eab5806f11d8f7a298f20aec0","_id":"@async-cancellables/async-lock@2.0.0","_nodeVersion":"18.13.0","_npmVersion":"9.3.1","dist":{"integrity":"sha512-pzNbeheIn6krGIhSiKXJazlXJeG10fmtk/HlqUS+XAUAwOZNOADdvdNCZ9n3G6b20jZMrvH7ljY3SEtkA3UD+A==","shasum":"8e35594623dc626939ddc18530c79ad8833e3aae","tarball":"https://registry.npmjs.org/@async-cancellables/async-lock/-/async-lock-2.0.0.tgz","fileCount":3,"unpackedSize":6355,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC42df8HgTbInKlWQuDBm1lCCh3Z/ZoV+qMLiwsmDFIuwIhAK0tToAPyF/ez3iIohCGC/0RdOFRA/nw8jhhwjM6uHyx"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkBGTJACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrbXw//YyzpqYCP4/g7Sl5P5CYddCUv1Z6lbUn9sEe/ruyPR33bEEXv\r\nIIsPUTryx+xKffD3Oi+cx5+hVUIMkPxjDI9TY93c63COcnLgTEso7aVmjca5\r\nN7Szo8CxuUOC/giOQSRbeBE/bIbq/HD4a+gg2y9zDvm7G2a8j8yjrHLXPg02\r\nBsqahcIHac1vIKf2GirvZ+eO4RCb0ZPJSr3jHE9YYcOn1Y6eJtWQyMuPyMNm\r\neBfM7q2vj/SSObtBCEMU8JCnfmwcXdQgAbLUFBi/tof39mBs7d2nvVqhlbZG\r\n2PkGLLWv9bS76GfJ2E4SyV0engSrdUbjO+dXEZ/XhqmnWJ0g7Jsz6hr0Xh6Y\r\nPa4iOtjfnZqfCNHwMrGaDVxT/DsAAIYZhrWAL6GLkBKBWzKjumwE2oilWe18\r\nAODFP5rlc4yB4ibIs/rDfIYNroPrrDuSZFrfoBE6EEvrmRSdxoxtOANQP1i/\r\nTPFHBFBU42HViR9PsUbCXuX+IbVoxEMFOBIZUzVHBt67LdvHbO9FRTRcO0Hz\r\nxOdXwa+Y0Bt3/QonY0gs1dSqXTJWFFL6lhOIV68bVLewOzmnF195banQ5LTI\r\nM8JUJZ9ul5APHYV7kXqC60U0LQL2mAxNEXPns+Bkg/4hDDhLDbQ86FCI1klw\r\nr+skFHv/vl/MCFjA314SVXQsKYwPwDpR+tw=\r\n=YoEb\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"vuwuv","email":"vkhubb@gmail.com"},"directories":{},"maintainers":[{"name":"vuwuv","email":"vkhubb@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/async-lock_2.0.0_1678009545473_0.15643105342343389"},"_hasShrinkwrap":false},"2.1.0":{"name":"@async-cancellables/async-lock","version":"2.1.0","description":"Asynchronous lock pool with priorities and cancellation support","main":"index.js","type":"module","repository":{"type":"git","url":"git+https://github.com/vuwuv/async-cancellables.git","directory":"packages/async-lock"},"keywords":["async","cancellable","AsyncLock","cancellation","lock"],"author":{"name":"vuwuv"},"license":"MIT","bugs":{"url":"https://github.com/vuwuv/async-cancellables/issues"},"homepage":"https://github.com/vuwuv/async-cancellables#readme","peerDependencies":{"@async-cancellables/ct":"^2.1.0"},"engines":{"node":">=18.0.0"},"gitHead":"286a1b8f801a432827adb845c47074d85aa338c6","_id":"@async-cancellables/async-lock@2.1.0","_nodeVersion":"18.13.0","_npmVersion":"9.3.1","dist":{"integrity":"sha512-uetXFoYZ/lbPMhw7Ou+ZrZMuzi5W0CX6/aLD0icM8mDbTnjmh6IYE3o369e/k7L/VcvBJx9u3kqNPF6ankd/bg==","shasum":"734f0906d1f6e41f552a2024627b3c85f11c48d7","tarball":"https://registry.npmjs.org/@async-cancellables/async-lock/-/async-lock-2.1.0.tgz","fileCount":3,"unpackedSize":6355,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC1cmiLlMKa/+plEYKkIm2Eg2XZPqyl/5tBARi46a01IQIgWV1ecq1IFzhY+Cx5zZpGF0nPiyPhB4wZw/S3GYZRn2I="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkB6WyACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp25Q/+Ilfo3QH8RYn/Agwa8SZkgo1zigtdERI4huGIi7cmF5JL6hoc\r\nQWvxCJGEBgKIdoMr48GDKb8H6XBh1utcbhFO205UEhzmCeJd7Tkhm5ZeWh0o\r\ns41k1weEyyiBSxHJYaDebnPpR7ddxuXjyUps2FFkQWYQYzZ1+f2S8IrAfYC4\r\nQ5ZbaXRBUX7tXPHA7+CxRcUBLLzbC49WPyJWquby1m4JqFMf0ayozyHLjn1g\r\nDNpkpeZ83+3Dyuo2iZne/ZzdSwME/apFxaRHt02fasYPtqdBiQ99kWSh6WPO\r\n/u1LukaxqkkGXrGsUZFv/i6zEYE38DRDk9vgaZIbKdkBV3TAOgypmn6SJo3d\r\nqARN6r1OS0eLWZjE2zqgptEpQtGwYXhCSadxYq6i1PDkHXe1QeZg0vONpgvw\r\n1gAtnN+s+R2I1aaz6g6ianZvMsHG59FtewSTgKtWlII41R5gysS9nu8400p6\r\nWswlefSSwaA3Ce/iRr3tTWqapagOpviSORdxtOsK6ePXIW/OIx3scckMy4kU\r\nhq746ulLr+RZvH86UIHs5y9O94t3hx/kTvaVag1C/E4YoylA0P3tHd6CGz/4\r\ntcm5Npu+DFqfNWmEzThg1/h1F4D0q114+SkQAa6Aj2WeuEfLP6ahgC00/M5c\r\nMYxFXSVRQBN1rYQSV/HvlzaTGgcgQq8l3jM=\r\n=vjQU\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"vuwuv","email":"vkhubb@gmail.com"},"directories":{},"maintainers":[{"name":"vuwuv","email":"vkhubb@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/async-lock_2.1.0_1678222769956_0.5512625886791909"},"_hasShrinkwrap":false},"2.2.0":{"name":"@async-cancellables/async-lock","version":"2.2.0","description":"Asynchronous lock pool with priorities and cancellation support","main":"index.js","type":"module","repository":{"type":"git","url":"git+https://github.com/vuwuv/async-cancellables.git","directory":"packages/async-lock"},"keywords":["async","cancellable","AsyncLock","cancellation","lock"],"author":{"name":"vuwuv"},"license":"MIT","bugs":{"url":"https://github.com/vuwuv/async-cancellables/issues"},"homepage":"https://github.com/vuwuv/async-cancellables#readme","peerDependencies":{"@async-cancellables/ct":"^2.1.0"},"engines":{"node":">=18.0.0"},"gitHead":"622cddddac93c248b2476f7b9240c9c6a2dba34b","_id":"@async-cancellables/async-lock@2.2.0","_nodeVersion":"18.15.0","_npmVersion":"9.3.1","dist":{"integrity":"sha512-eaMuJwBGCRUkg0Ht+GAsBB9IjopvQj7iKtqtadt1F/Amui+25N1G7cbfOi5IQtIVICz/x5tHowLo2jzJQipWWQ==","shasum":"330a85ae7ea1439c2c94ece6fd293668975f9a63","tarball":"https://registry.npmjs.org/@async-cancellables/async-lock/-/async-lock-2.2.0.tgz","fileCount":3,"unpackedSize":6479,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDv+Tod2guIwKijuNSASCZo6lj0N4hfCIKVy1M0asMCsAIgevxN1b/+81tpGUlrk3IgBwsDeqFbO5lAhRFJE034o+A="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkEvMaACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpkmBAAl5/j+TSKH++yRdtYJaipIhGPYLzmyDKr/znZnCrDGkJ+jqtx\r\nYASnwv3HqFweCn0GCyeeN7ceVMPRAtbKyxpRrOf9ng1dCkGV/HkvQcV/3F0P\r\nx4VXfZI3JolFdH7POwiRL+RBdN5OpYeBoR++bszDP/8io3nENVJwwBEh2ZIo\r\n2MP9ISDA+/O0R5psj7vSU5FYuSxJOZ+WxiXFuy8ogs6RS2C2RrNRKM/SXc+E\r\nS6k5NGWN5gcwjupQdcLXdhJVs+doyNaqH8dVA1HcIlazqv27xVc4Dw/ZXdoL\r\nqpUvOyBmv6X4VmxiHcZ/biUR7/pCOGzUyo7anKPoTVPV+jvBQ4f8nmNQPOxE\r\n0zTBUI9+NxCFjkaG1wb07BLkZYeD1tzdU+uIkMHKifD5IeABpMKleHYN3O/L\r\nXe1AweXtQyBXPyUNo3csxA4esDxPIK9x+/TMmWlOoTYivGwCNFf7g/MFzf6i\r\nZc8iSbGtONZBYd99juwg2HOaQXNmBg2Rut/ergy/ZnEltP0YxHbbUDAWNZmc\r\n7Myzl8JH0P0zCLZ2EMQF3atAlZL2qDOj8hoOxtZEzf8BYlB4FXaJunJY6oSK\r\nSJYkNWsa5sVnd/r1Dj59+WX4AwMpowYtaXqCdwFEn9XMAjuTVhp/HmfIsVwu\r\n78wYj5aVrVGRGltQkov2rZb2+BhqxV6tsIg=\r\n=6H9w\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"vuwuv","email":"vkhubb@gmail.com"},"directories":{},"maintainers":[{"name":"vuwuv","email":"vkhubb@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/async-lock_2.2.0_1678963482366_0.2772626040313557"},"_hasShrinkwrap":false}},"time":{"created":"2023-03-05T09:45:45.409Z","2.0.0":"2023-03-05T09:45:45.681Z","modified":"2023-03-16T10:44:42.775Z","2.1.0":"2023-03-07T20:59:30.113Z","2.2.0":"2023-03-16T10:44:42.609Z"},"maintainers":[{"name":"vuwuv","email":"vkhubb@gmail.com"}],"description":"Asynchronous lock pool with priorities and cancellation support","homepage":"https://github.com/vuwuv/async-cancellables#readme","keywords":["async","cancellable","AsyncLock","cancellation","lock"],"repository":{"type":"git","url":"git+https://github.com/vuwuv/async-cancellables.git","directory":"packages/async-lock"},"author":{"name":"vuwuv"},"bugs":{"url":"https://github.com/vuwuv/async-cancellables/issues"},"license":"MIT","readme":"# Async Cancellables / AsyncLock\n\n> Asynchronous lock class allows to limit simultaneous resource access supporting prioritized access and cancellation tokens\n\n## Table of contents\n\n- [Prerequisites](#prerequisites)\n- [Table of contents](#table-of-contents)\n- [Installation](#installation)\n- [API](#api)\n    - [Creating lock](#creating-lock)\n    - [Waiting slots](#waiting-slots)\n    - [Releasing slots](#releasing-slots)\n    - [Accessing properties](#accessing-properties)\n- [Authors](#authors)\n- [License](#license)\n\n## Prerequisites\n\nThis project requires NodeJS (version 18 or later) and NPM.\n\n## Installation\n\nTo install and set up the library, run:\n\n```sh\n$ npm install @async-cancellables/async-state\n```\n\n## Example\n\nThe following example downloads a list of files having no more than 2 concurrent downloads\n\n```js\nimport AsyncLock from '@async-cancellables/async-lock';\nconst lock = new AsyncLock(2);\n\nasync downloadFile(url) {\n    let ticket = await lock.waitOne();\n    try {\n        ...\n    }\n    finally {\n        lock.release(ticket);\n    }\n}\n\nconst files = await Promise.all(urls.map(url => downloadFile(lock, url)));\n```\n\n## API\n\n### Creating lock\n\n`new AsyncLock(totalSlots = 1)` creates new lock with `totalSlots` of slots.\n\n### Waiting for slots\n\nThere are several wait methods:\n- `waitOne(cancellationToken = null)` waits for one slot to be available\n- `wait(slotCount, cancellationToken = null)` waits for `slotCount` slots to be available\n- `waitPrioritized(slotCount, priority, cancellationToken = null)` waits with specified\n\nAll of them return `ticket` to be used for lock release. Default priority is `0`, the higher it is the sooner wait method returns.\n\n### Releasing slots\n\n- `release(ticket)` releases slot count locked by any of the wait methods\n\nAnother way to release slots used by `ticket` is to call `release()` method of the ticket: `ticket.release()`\n\n### Accessing properties\n\n- `totalSlots` gets or sets total slots of the lock\n- `usedSlots` gets slot count currently occupied\n- `availableSlots` get slot count currently available\n- `waitersPresent` returns presence of any waiters in the queue\n- `waitersCount` returns count of waiters in the queue\n\n## Authors\n\n* **vuwuv** - *Initial work* - [vuwuv](https://github.com/vuwuv)\n\n## License\n\n[MIT License] © vuwuv","readmeFilename":"README.md"}