{"_id":"async-rwlock","_rev":"3-615821522acf43f76dbea6604ba16a49","name":"async-rwlock","dist-tags":{"latest":"1.1.1","1.1.0":"1.1.0"},"versions":{"1.0.0":{"name":"async-rwlock","version":"1.0.0","description":"Promise-based asynchronous readers-writers lock","main":"dist/index.js","scripts":{"build":"rimraf dist && tsc","lint":"tslint --project ./tsconfig.json","prepublishOnly":"yarn build","test":"jest"},"repository":{"type":"git","url":"git+https://github.com/mvisat/async-rwlock.git"},"keywords":["async","concurrency","lock","rwlock","promise"],"author":{"name":"Muhamad Visat Sutarno"},"license":"MIT","bugs":{"url":"https://github.com/mvisat/async-rwlock/issues"},"homepage":"https://github.com/mvisat/async-rwlock#readme","devDependencies":{"@types/jest":"^23.3.1","@types/node":"^10.7.1","jest":"^23.5.0","rimraf":"^2.6.2","ts-jest":"^23.1.3","tslint":"^5.11.0","tslint-eslint-rules":"^5.4.0","typescript":"^3.0.1"},"engines":{"node":">=8.0.0"},"gitHead":"bc87dd7278b260db35a18cd4c1962c9df0ea3389","_id":"async-rwlock@1.0.0","_npmVersion":"5.6.0","_nodeVersion":"8.11.4","_npmUser":{"name":"mvisat","email":"mvisat@gmail.com"},"dist":{"integrity":"sha512-SEMbHBPGDIgFWJqDPqX8BGipIdNVERrpjFiiQgU14M9Qb2hVCJJJ/zgM4ysZyFyy2rabzk/9PiVbN1Hw5oRq3A==","shasum":"ca83954b1f9e6032ba297d349f8c10c4e84e3ab3","tarball":"https://registry.npmjs.org/async-rwlock/-/async-rwlock-1.0.0.tgz","fileCount":12,"unpackedSize":26912,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbd3LFCRA9TVsSAnZWagAA+AEP/1uCBcXrBoouYuuyG1/v\nPOskQKbIaKEa5R5Ys5R6ylSh/vDQlhizY0aVgTJJsxkdgCk7KCqxOh6jpUA8\nORYlvI6oHjS//0/X19Gfbc7eA5/wwCAAojf+Aj5AMy8fiQ256vGIvKxFn+BB\nc4BMGT/SWXTdRKrU9uMqgJNrK0BSjvtDldK4np8GNX/9Lzq52qD3L89WEf2f\nNaqx03ltjbhoy9JEae14CPcFHwRn9gEyCGixwh2zjPQbpOHn+/dU3NP3DiZ2\nJl7kd8zOoWxoUYvaEmKaEONspJvajphBhIOcMzkA2uQGpUP4e7JLf6Yq/4/g\n+/OvglBJe/o34dKIXcjfN807u/CwfpzwV3GLzKSx95vEoxRsr/4kKNbECzU8\n6+/lgb/Q/4tWrjZcAjdkanbJmEC2QTsk24BQ4uxuHyh7GqUES6JE/jQy54cj\necPErIfyVKfMjxnTF9QqosnygrJfRjl/377B97t/YBiJNFnoZun0QLVAiRvD\nJDUx9fsZ/QGF33SLH9C9lewOvmkOt0+smUEewHsVk8txYwu14muP1rjsTzOc\nsnJ3PjodOj1VzLf1oNzrJ/KYFiTzfdGhmfRzSo1xM1wyYpLCwIPY/XV5VTRS\nHwwb1crWDXzcG6W+SZcg+qDUs9l7tLL8gHjfK5jIxc+beCyEl6uv13fGxF7S\n+yzp\r\n=ppnz\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEfhehrOwXgZqTM4zw1/Wnivi+r6eYCJP1+3aYbZ0e42AiEAs4Pyhwqb8OHYryeB3snYH5fthAIC8+4nNkxBOcAs13g="}]},"maintainers":[{"name":"mvisat","email":"mvisat@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/async-rwlock_1.0.0_1534554820464_0.15528727361259453"},"_hasShrinkwrap":false},"1.1.0":{"name":"async-rwlock","version":"1.1.0","description":"Promise-based asynchronous readers-writers lock","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc","lint":"tslint --project tsconfig.json","pretty":"yarn lint && prettier --write 'src/**/*.ts'","test":"nyc mocha","preversion":"yarn lint && yarn test","postversion":"git push --tags && yarn publish . --tag $npm_package_version && git push"},"repository":{"type":"git","url":"git+https://github.com/mvisat/async-rwlock.git"},"keywords":["async","concurrency","lock","rwlock","promise"],"author":{"name":"Muhamad Visat Sutarno"},"license":"MIT","bugs":{"url":"https://github.com/mvisat/async-rwlock/issues"},"homepage":"https://github.com/mvisat/async-rwlock#readme","engines":{"node":">=8.0.0"},"devDependencies":{"@types/chai":"^4.1.7","@types/chai-as-promised":"^7.1.0","@types/mocha":"^5.2.5","@types/node":"^10.12.21","chai":"^4.2.0","chai-as-promised":"^7.1.1","mocha":"^5.2.0","nyc":"^13.1.0","prettier":"^1.16.4","source-map-support":"^0.5.10","ts-node":"^8.0.2","tslint":"^5.12.1","tslint-config-prettier":"^1.18.0","typescript":"^3.3.1"},"nyc":{"extension":[".ts"],"require":["ts-node/register"],"include":["src/**/*.ts"],"exclude":["**/*.d.ts","src/**/index.ts"],"reporter":["text","html"],"all":true},"readmeFilename":"README.md","readme":"# async-rwlock\nPromise-based asynchronous readers-writers lock. Timeout is also supported.\n\n## Install\n```\n$ npm install --save async-rwlock\n```\nor\n```\n$ yarn add async-rwlock\n```\n\n## Quick Usage\n\n```js\nconst RWLock = require('async-rwlock').RWLock;\n\nconst lock = new RWLock();\n\nlock.readLock()\n.then(() => {\n    console.log('read lock acquired');\n    lock.unlock();\n});\n\nlock.writeLock()\n.then(() => {\n    console.log('write lock acquired');\n    lock.unlock();\n});\n```\n\n### Async/Await\n\n```ts\nimport RWLock from 'async-rwlock';\n\nasync function testLock() {\n    const lock = new RWLock();\n\n    await lock.readLock();\n    console.log('read lock acquired');\n    lock.unlock();\n\n    await lock.writeLock();\n    console.log('write lock acquired');\n    lock.unlock();\n}\n\n(async () => { await testLock(); })();\n```\n\n## Advanced Usage\n\n### Timeout\n```js\nconst RWLock = require('async-rwlock').RWLock;\n\nconst lock = new RWLock();\n\nlock.readLock()\n.then(() => {\n    console.log('read lock acquired');\n    // lock.unlock() // oops!\n});\n\nlock.writeLock(1000) // 1 second\n.then(() => {\n    console.log('write lock will never be acquired');\n})\n.catch((err) => {\n    console.error('promise will be rejected if timeout occured');\n    console.error(err);\n});\n```\n\n#### Async/Await\n\n```ts\nimport RWLock from 'async-rwlock';\n\nasync function testLock() {\n    const lock = new RWLock();\n\n    await lock.readLock();\n    console.log('read lock acquired');\n    // lock.unlock() // oops!\n\n    try {\n        await lock.writeLock(1000); // 1 second\n        console.log('write lock will never be acquired');\n    } catch (err) {\n        console.error('error will be thrown if timeout occured');\n        console.error(err);\n    }\n}\n\n(async () => { await testLock(); })();\n```\n\n## API\n\n### `new RWLock()`\n- Returns: instance of `RWLock`.\n\n#### `readLock([timeout])`\n- `timeout?: number`. **Default**: `Infinity`.\n- Returns: `Promise<void>`.\n\n#### `writeLock([timeout])`\n- `timeout?: number`. **Default**: `Infinity`.\n- Returns: `Promise<void>`.\n\nAcquire a read/write lock.\n\n`timeout` is how long it will wait to acquire the lock before promise is rejected in milliseconds. If `timeout` is not in range `0 <= timeout < Infinity`, it will wait indefinitely.\n\n#### `unlock()`\n- Returns: `void`.\n\nRelease current lock. Must be called after operation using read/write lock is finished.\n\n#### `getState()`\n- Returns: `State`.\n\nGet current state of lock. The states are either `Idle`, `Reading`, or `Writing`.\n\n## License\n[MIT](LICENSE)\n","licenseText":"MIT License\n\nCopyright (c) Muhamad Visat Sutarno\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"async-rwlock@1.1.0","dist":{"shasum":"30154af56e38129959ba847bf318047f41432e08","integrity":"sha512-ar1mbaLe2ww08wafoRqsmrpqiOGas4rhd4UP4hbC+3r3a6VJ/7lenc4XCzgl8+jaFzrFoambWj8upDyoMRdEng==","tarball":"https://registry.npmjs.org/async-rwlock/-/async-rwlock-1.1.0.tgz","fileCount":11,"unpackedSize":14374,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcWGC2CRA9TVsSAnZWagAAgqEP/jTmT327zTR5enyBR6ys\nse7hGRCf9a9MiS0kI6GhLGP+Z/IJDjssr3R1BOz+0L8DW8JR6f+y74seNI19\n3bRywZLRx1ehrG/eFJdIgo8hvcJJZPsZxrnpGHvgj16amfB6b0BqzYw0mccZ\nc3sD0ge9GRSPGFO324r/Cb+Xxuu9PDl2gF6kPvu3w/KOJWEAhE/olZvmpPUA\nkHg7PKhqHBj6S6rxNvpRvIf4JETXS8GmS0cl5CccvyJeINbf69jBp9dwqvlA\nmQh3pOVa1jusL4SxlXSCFsdOQoLB3C3MME0sxeSKV+kR5reqqo3v+XsbyF1j\n45VkcHaKjDwET1mmmLGryA0va4YqW0pgc23TLgnwiBIl22kgiqb1PqCPYt8T\nQJ0qFlaC8XLztEJhJOc0+p9x2U7lQse5xx1QjlNAFJMv7SfSvwq1FU2ZUnjR\nve8ti8E1e07/9M1hPCuzRd4PwzcSYcmsMyTxXLFFy0bdINudjrT8DQHeZNRY\nWppSIIs/pX1EYuAB52EyTUl3z71l6+uzFU22V53DohCfd8ko9Qo2w8A6VOet\nxIAv1rtRlJ+XFF3S7xvX4igq6RHUTojEyBCTKsJJo1AzszLbMnJYQWmFJcTc\nKc6WiCm8oKj5PwtAJ2PCwNdudcqLKVqyyx3ApO8T+qlTJg3RQceieCCQAiBv\n1uSz\r\n=8fUB\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD37hxNbJR+WHSrM9YX0VyswT6sBfggGpxXSvHMYAGuUQIhAICGayb6aIy7K3edxs0ThOTZWepZy/TKTbaBLEzIckiq"}]},"maintainers":[{"name":"mvisat","email":"mvisat@gmail.com"}],"_npmUser":{"name":"mvisat","email":"mvisat@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/async-rwlock_1.1.0_1549295797780_0.7945033926161311"},"_hasShrinkwrap":false},"1.1.1":{"name":"async-rwlock","version":"1.1.1","description":"Promise-based asynchronous readers-writers lock","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc","lint":"tslint --project tsconfig.json","pretty":"yarn lint && prettier --write 'src/**/*.ts'","test":"nyc mocha","preversion":"yarn lint && yarn test","postversion":"git push --tags && yarn publish && git push"},"repository":{"type":"git","url":"git+https://github.com/mvisat/async-rwlock.git"},"keywords":["async","concurrency","lock","rwlock","promise"],"author":{"name":"Muhamad Visat Sutarno"},"license":"MIT","bugs":{"url":"https://github.com/mvisat/async-rwlock/issues"},"homepage":"https://github.com/mvisat/async-rwlock#readme","engines":{"node":">=8.0.0"},"devDependencies":{"@types/chai":"^4.1.7","@types/chai-as-promised":"^7.1.0","@types/mocha":"^5.2.5","@types/node":"^10.12.21","chai":"^4.2.0","chai-as-promised":"^7.1.1","mocha":"^5.2.0","nyc":"^13.1.0","prettier":"^1.16.4","source-map-support":"^0.5.10","ts-node":"^8.0.2","tslint":"^5.12.1","tslint-config-prettier":"^1.18.0","typescript":"^3.3.1"},"nyc":{"extension":[".ts"],"require":["ts-node/register"],"include":["src/**/*.ts"],"exclude":["**/*.d.ts","src/**/index.ts"],"reporter":["text","html"],"all":true},"licenseText":"MIT License\n\nCopyright (c) Muhamad Visat Sutarno\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"async-rwlock@1.1.1","dist":{"shasum":"6662c732aa2950969b5bdc085ef568fa7adfb97a","integrity":"sha512-K4ecpHLAc0Jul4dMb1KLpukblQmHxD5/HNgkTuO3sQ9oLLtVENCJVk7+b0wMj1K89cqnjGkTsAvOb83lCfoKwA==","tarball":"https://registry.npmjs.org/async-rwlock/-/async-rwlock-1.1.1.tgz","fileCount":11,"unpackedSize":14345,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcWGM9CRA9TVsSAnZWagAAL/4P/Axe6XXiIkf9mP37LZeM\nD55FJIIUpIGjT+OFjgYK6mR+PnND23T4/md1NnsTJ75UZ+FZkzsUOtJJUldB\nLYd1JlVb6cVcRi0cVUqGG074BS/AmGAMCfjb5MFnQDv3imGrL+EL5eC8qKtE\n7nohfSpePSg0dX4/EQdme1Z/TlzF3c+esTgL2N2Dh/m2yFVr6TgNuEOkP0gh\ncQFLuOYjvDInQbF2neyDwdKForSPdecACrqqb4BXXKd6VMboeGCBPDQhRA6G\n7VdsruYxHzBQnarmcgam/suX8hHRtWWpwNtXXR54h7VHB0oxCgvJ7j3xgpZp\nbKrsfk94DGC2SLMTI3RY+I5Pcgy93FW1dbiY9OfnBudxIo5Bu79U16NrGLcj\ngwqeB1THGLvg86c1v6RgjXYuVDdp9aqxeaBbMtxYzacChF3W4aq8dfb3WzTI\nxWsY3rAoIODPHIZMilVQ/D8m+6eyYPHOeO85CBK4yQiRgiz/AmiJyivOaGMs\nnAHs27srQ6axrNfOtZJAuunyTrmtX+iS7XU9OxV7YHzsrPYadUC5jY/XMrFn\nXkEKatfvmiQVZUlgw3nSqfRBmlo5RHytyfykJCkLGc39/qEcQCmLJVsKhdU1\nWP7YAX43Ewtg23IQ84jgCdT7xt1oh97QJaiQIqFVA+qZuqlnf38cfLpzaVQF\nIFxC\r\n=/lIg\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCC1sXEnWLc48+Ft/EksVtJ9so5Mb8kR/FfLrrSpxztzwIhAPkY3/o351QdDunxPH5/ERUaGBWW8VhsYmwRLLmNC+oI"}]},"maintainers":[{"name":"mvisat","email":"mvisat@gmail.com"}],"_npmUser":{"name":"mvisat","email":"mvisat@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/async-rwlock_1.1.1_1549296444635_0.47921980448275225"},"_hasShrinkwrap":false}},"time":{"created":"2018-08-18T01:13:40.463Z","1.0.0":"2018-08-18T01:13:40.531Z","modified":"2022-04-11T15:35:10.543Z","1.1.0":"2019-02-04T15:56:37.891Z","1.1.1":"2019-02-04T16:07:24.777Z"},"maintainers":[{"name":"mvisat","email":"mvisat@gmail.com"}],"description":"Promise-based asynchronous readers-writers lock","homepage":"https://github.com/mvisat/async-rwlock#readme","keywords":["async","concurrency","lock","rwlock","promise"],"repository":{"type":"git","url":"git+https://github.com/mvisat/async-rwlock.git"},"author":{"name":"Muhamad Visat Sutarno"},"bugs":{"url":"https://github.com/mvisat/async-rwlock/issues"},"license":"MIT","readme":"# async-rwlock\nPromise-based asynchronous readers-writers lock. Timeout is also supported.\n\n## Install\n```\n$ npm install --save async-rwlock\n```\nor\n```\n$ yarn add async-rwlock\n```\n\n## Quick Usage\n\n```js\nconst RWLock = require('async-rwlock').RWLock;\n\nconst lock = new RWLock();\n\nlock.readLock()\n.then(() => {\n    console.log('read lock acquired');\n    lock.unlock();\n});\n\nlock.writeLock()\n.then(() => {\n    console.log('write lock acquired');\n    lock.unlock();\n});\n```\n\n### Async/Await\n\n```ts\nimport RWLock from 'async-rwlock';\n\nasync function testLock() {\n    const lock = new RWLock();\n\n    await lock.readLock();\n    console.log('read lock acquired');\n    lock.unlock();\n\n    await lock.writeLock();\n    console.log('write lock acquired');\n    lock.unlock();\n}\n\n(async () => { await testLock(); })();\n```\n\n## Advanced Usage\n\n### Timeout\n```js\nconst RWLock = require('async-rwlock').RWLock;\n\nconst lock = new RWLock();\n\nlock.readLock()\n.then(() => {\n    console.log('read lock acquired');\n    // lock.unlock() // oops!\n});\n\nlock.writeLock(1000) // 1 second\n.then(() => {\n    console.log('write lock will never be acquired');\n})\n.catch((err) => {\n    console.error('promise will be rejected if timeout occured');\n    console.error(err);\n});\n```\n\n#### Async/Await\n\n```ts\nimport RWLock from 'async-rwlock';\n\nasync function testLock() {\n    const lock = new RWLock();\n\n    await lock.readLock();\n    console.log('read lock acquired');\n    // lock.unlock() // oops!\n\n    try {\n        await lock.writeLock(1000); // 1 second\n        console.log('write lock will never be acquired');\n    } catch (err) {\n        console.error('error will be thrown if timeout occured');\n        console.error(err);\n    }\n}\n\n(async () => { await testLock(); })();\n```\n\n## API\n\n### `new RWLock()`\n- Returns: instance of `RWLock`.\n\n#### `readLock([timeout])`\n- `timeout?: number`. **Default**: `Infinity`.\n- Returns: `Promise<void>`.\n\n#### `writeLock([timeout])`\n- `timeout?: number`. **Default**: `Infinity`.\n- Returns: `Promise<void>`.\n\nAcquire a read/write lock.\n\n`timeout` is how long it will wait to acquire the lock before promise is rejected in milliseconds. If `timeout` is not in range `0 <= timeout < Infinity`, it will wait indefinitely.\n\n#### `unlock()`\n- Returns: `void`.\n\nRelease current lock. Must be called after operation using read/write lock is finished.\n\n#### `getState()`\n- Returns: `State`.\n\nGet current state of lock. The states are either `Idle`, `Reading`, or `Writing`.\n\n## License\n[MIT](LICENSE)\n","readmeFilename":"README.md"}