{"_id":"rwlock","_rev":"36-2739ba48bb07dfd94d32dd1685b06fe5","name":"rwlock","description":"A read/write lock implementation for Node.","dist-tags":{"latest":"5.0.0"},"versions":{"1.0.0":{"name":"rwlock","version":"1.0.0","description":"Read-write lock implementation for Node.","keywords":"read write lock locker reader writer","homepage":"https://github.com/canvace/ReadWriteLock","bugs":"https://github.com/canvace/ReadWriteLock/issues","author":{"name":"Alberto La Rocca","email":"a71104@gmail.com","url":"https://github.com/71104"},"files":["rwlock.js"],"main":"rwlock.js","repository":{"type":"git","url":"https://github.com/canvace/ReadWriteLock.git"},"_id":"rwlock@1.0.0","dist":{"shasum":"e6b5751193088b474962b8d28a771bd30de914f6","tarball":"https://registry.npmjs.org/rwlock/-/rwlock-1.0.0.tgz","integrity":"sha512-N4EGsDmxgKH/JPTN4gIQNIAK0XuA89jzeDXvnFmYnp9JK0cU6QjjxgLOCRibRJnIgK969BANY2LGwJzjGIriag==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDQMXiW1LkdxzuWfYCTZGQRafMo+7cRIlAWsIr2PGTDqQIhALyHpUX+gcMFM9QO0w3LAj10mf9F1u1svIYc4UbXAZAM"}]},"_npmVersion":"1.1.69","_npmUser":{"name":"71104","email":"a71104@gmail.com"},"maintainers":[{"name":"71104","email":"a71104@gmail.com"}],"directories":{}},"1.0.1":{"name":"rwlock","version":"1.0.1","description":"Read-write lock implementation for Node.","keywords":["read","write","lock","locker","reader","writer"],"homepage":"https://github.com/canvace/ReadWriteLock","bugs":"https://github.com/canvace/ReadWriteLock/issues","author":{"name":"Alberto La Rocca","email":"a71104@gmail.com","url":"https://github.com/71104"},"files":["rwlock.js"],"main":"rwlock.js","repository":{"type":"git","url":"https://github.com/canvace/ReadWriteLock.git"},"_id":"rwlock@1.0.1","dist":{"shasum":"6388433ee90abb9d0fc0ef0da7ce7a6b5ec69c20","tarball":"https://registry.npmjs.org/rwlock/-/rwlock-1.0.1.tgz","integrity":"sha512-MtDx4T0WNg6YiV/OiKLnRC3FmU0naZAQaFBBOVfxj5eV9crhRAV8JzPtf1Y1qGSI5GcAvUHV0yhR7OFVYFopoQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCiD/PCyV4J1wAiodcIvYZWMLGu6GLoiiPx+fot3/RFiAIhALXvD1tEAF1Paz2fkBsvpW/U03R26sVeYzbWhAI/f8+0"}]},"_npmVersion":"1.1.69","_npmUser":{"name":"71104","email":"a71104@gmail.com"},"maintainers":[{"name":"71104","email":"a71104@gmail.com"}],"directories":{}},"2.0.0":{"name":"rwlock","version":"2.0.0","description":"Read-write lock implementation for Node.","keywords":["read","write","lock","locker","reader","writer"],"homepage":"https://github.com/canvace/ReadWriteLock","bugs":"https://github.com/canvace/ReadWriteLock/issues","author":{"name":"Alberto La Rocca","email":"a71104@gmail.com","url":"https://github.com/71104"},"files":["rwlock.js"],"main":"rwlock.js","repository":{"type":"git","url":"https://github.com/canvace/ReadWriteLock.git"},"_id":"rwlock@2.0.0","dist":{"shasum":"31cdab24b74d46363b8da6a6ffc61c9992bc75a1","tarball":"https://registry.npmjs.org/rwlock/-/rwlock-2.0.0.tgz","integrity":"sha512-+71qgDQ1apiIUEtzWGss9BGesmi228OjjJuhtGptfW4tXaMSuXkUhHu5jILoXR2/mr+LQzmF9kTGhcFo8nKfHA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEHllth88Eg/jUkNQ3FovafNFO6kawuQIZYLp+Vzhy3YAiBdHXhuSFqPsEq5YdPOysjKfSCZKQCgS4i4ORXVawvBmw=="}]},"_npmVersion":"1.1.69","_npmUser":{"name":"71104","email":"a71104@gmail.com"},"maintainers":[{"name":"71104","email":"a71104@gmail.com"}],"directories":{}},"2.1.0":{"name":"rwlock","version":"2.1.0","description":"Read-write lock implementation for Node.","keywords":["read","write","lock","locker","reader","writer"],"homepage":"https://github.com/canvace/ReadWriteLock","bugs":"https://github.com/canvace/ReadWriteLock/issues","author":{"name":"Alberto La Rocca","email":"a71104@gmail.com","url":"https://github.com/71104"},"files":["rwlock.js"],"main":"rwlock.js","repository":{"type":"git","url":"https://github.com/canvace/ReadWriteLock.git"},"_id":"rwlock@2.1.0","dist":{"shasum":"d4c9e630a8b0a04f7178c2390ebcc19d1a1baeff","tarball":"https://registry.npmjs.org/rwlock/-/rwlock-2.1.0.tgz","integrity":"sha512-WqRgmrHlPq2EqmurkJDKhq9tE8a+j5XBdUJ0dY1mT5Ik4GktbcbPetHtHyLNFWixEO4666l/uXjIFs3HgOt7hA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDEkBRQjN6D0xZ4Mzsk3LjdLa/8jbf1M6tOBJ2lZawDiQIhAKHaPTQgZlxnmiyiFmvFg+WXGw825V8JQKlo1ptzMTun"}]},"_npmVersion":"1.1.69","_npmUser":{"name":"71104","email":"a71104@gmail.com"},"maintainers":[{"name":"71104","email":"a71104@gmail.com"}],"directories":{}},"2.1.1":{"name":"rwlock","version":"2.1.1","description":"Read-write lock implementation for Node.","keywords":["read","write","lock","locker","reader","writer"],"homepage":"https://github.com/canvace/ReadWriteLock","bugs":"https://github.com/canvace/ReadWriteLock/issues","author":{"name":"Alberto La Rocca","email":"a71104@gmail.com","url":"https://github.com/71104"},"files":["rwlock.js"],"main":"rwlock.js","repository":{"type":"git","url":"https://github.com/canvace/ReadWriteLock.git"},"_id":"rwlock@2.1.1","dist":{"shasum":"665ebaafc6f26e5e4497d34b6a2fbccbe82f950e","tarball":"https://registry.npmjs.org/rwlock/-/rwlock-2.1.1.tgz","integrity":"sha512-lgx350VtWnf6R5BkBjksceM4gUAxvdSx6avshkMY9Ma1HSVy1oD+pFV5DqB9m+qkF2ZdryjCDwvjxEbLv+fXXw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCNEbJVJXmD4no0eb3U9shaOij6CxT6IHP67wpEw/3s6wIgRpxEHnaNzHVjyvQDvHLr7GsIlbdI/vSig9hd2iBz90I="}]},"_npmVersion":"1.1.69","_npmUser":{"name":"71104","email":"a71104@gmail.com"},"maintainers":[{"name":"71104","email":"a71104@gmail.com"}],"directories":{}},"2.1.2":{"name":"rwlock","version":"2.1.2","description":"Read-write lock implementation for Node.","keywords":["read","write","lock","locker","reader","writer"],"homepage":"https://github.com/canvace/ReadWriteLock","bugs":"https://github.com/canvace/ReadWriteLock/issues","author":{"name":"Alberto La Rocca","email":"a71104@gmail.com","url":"https://github.com/71104"},"files":["rwlock.js"],"main":"rwlock.js","repository":{"type":"git","url":"https://github.com/canvace/ReadWriteLock.git"},"_id":"rwlock@2.1.2","dist":{"shasum":"3eb1a0941241a8b602ba2091001840469c206bbc","tarball":"https://registry.npmjs.org/rwlock/-/rwlock-2.1.2.tgz","integrity":"sha512-FskD9+VSA7cwgwXGo6rcNTy3WC74h/dweWqf4mtFar6SQxtvw9n1rCHLsKBxOa5gjBkvu7g/qNBuZ4QVkBUJpw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEtV0fxOxGuI2ToQuJZalWsqN5JXTuUQe1xEy7vR38yIAiEApp+ml4ywLTbf6FTsgSxTor+k7mbNVYrFL5CD+SGLVvY="}]},"_npmVersion":"1.1.69","_npmUser":{"name":"71104","email":"a71104@gmail.com"},"maintainers":[{"name":"71104","email":"a71104@gmail.com"}],"directories":{}},"3.2.0":{"name":"rwlock","version":"3.2.0","description":"A read/write lock implementation for Node.","homepage":"http://71104.github.io/rwlock","bugs":{"url":"https://github.com/71104/rwlock/issues"},"license":"MIT","author":{"name":"Alberto La Rocca","email":"a71104@gmail.com"},"files":["lib","LICENSE","README.md"],"main":"lib/lock.js","repository":{"type":"git","url":"https://github.com/71104/rwlock.git"},"devDependencies":{"grunt":"~0.4.2","grunt-contrib-clean":"~0.5.0","grunt-contrib-jshint":"~0.7.2","grunt-contrib-uglify":"~0.2.7","grunt-contrib-yuidoc":"~0.5.0","grunt-contrib-nodeunit":"~0.2.2"},"_id":"rwlock@3.2.0","dist":{"shasum":"7afbf7d0f32486cc895f7072d0bd169b3c28bde3","tarball":"https://registry.npmjs.org/rwlock/-/rwlock-3.2.0.tgz","integrity":"sha512-L+yEhgzqmuUIUFMkisPkQ4n+5ivhWj0Q8ojdMOA7tDg6QJPACzy8aeKKG4l4hyoRkgfupYeajweOGveCxrXSHg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEKo9wF2eRSjBrG0BQLnP4s0sx1Icq3ayp4PAE5U5CTYAiBwiY3SFT2TpKU/6qg6d7Y0FYxIqbREO3xVXfOu49Zj+A=="}]},"_from":".","_npmVersion":"1.3.5","_npmUser":{"name":"71104","email":"a71104@gmail.com"},"maintainers":[{"name":"71104","email":"a71104@gmail.com"}]},"4.0.0":{"name":"rwlock","version":"4.0.0","description":"A read/write lock implementation for Node.","homepage":"http://71104.github.io/rwlock","bugs":{"url":"https://github.com/71104/rwlock/issues"},"license":"MIT","author":{"name":"Alberto La Rocca","email":"a71104@gmail.com"},"files":["lib","LICENSE","README.md"],"main":"lib/lock.js","repository":{"type":"git","url":"https://github.com/71104/rwlock.git"},"devDependencies":{"grunt":"~0.4.2","grunt-contrib-clean":"~0.5.0","grunt-contrib-jshint":"~0.7.2","grunt-contrib-uglify":"~0.2.7","grunt-contrib-yuidoc":"~0.5.0","grunt-contrib-nodeunit":"~0.2.2"},"_id":"rwlock@4.0.0","dist":{"shasum":"e5dce97f412991046368e4a6e3d12693f6ca6cbc","tarball":"https://registry.npmjs.org/rwlock/-/rwlock-4.0.0.tgz","integrity":"sha512-MsZNAVonGYPpTR6LP0KNs7S/dultFdP5i3YRi+FBPTMTVB5IkUQ1ErOpRdDnkGOVtYpTYIkQq7dfoAhSvAqoWA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDYfeBurgUFaQ92txtxS+keh5z4Xw6AG5GXHIiLdeg5sAIgKVOy0wg4lXTD4oJWL+jio2ZroNd5nWJ2Q3XJS90GgvU="}]},"_from":".","_npmVersion":"1.3.5","_npmUser":{"name":"71104","email":"a71104@gmail.com"},"maintainers":[{"name":"71104","email":"a71104@gmail.com"}]},"5.0.0":{"name":"rwlock","version":"5.0.0","description":"A read/write lock implementation for Node.","homepage":"http://71104.github.io/rwlock","bugs":{"url":"https://github.com/71104/rwlock/issues"},"license":"MIT","author":{"name":"Alberto La Rocca","email":"a71104@gmail.com"},"contributors":[{"name":"Alberto La Rocca","email":"a71104@gmail.com"},{"name":"Christian Lerrahn","email":"git@penpal4u.net"}],"files":["lib","LICENSE","README.md"],"main":"lib/lock.js","repository":{"type":"git","url":"https://github.com/71104/rwlock.git"},"devDependencies":{"grunt":"~0.4.2","grunt-contrib-clean":"~0.5.0","grunt-contrib-jshint":"~0.7.2","grunt-contrib-uglify":"~0.2.7","grunt-contrib-yuidoc":"~0.5.0","grunt-contrib-nodeunit":"~0.2.2"},"gitHead":"255612733f2b2687b8ee146531e1ab690e962363","_id":"rwlock@5.0.0","scripts":{},"_shasum":"888d6a77a3351cc1a209204ef2ee1722093836cf","_from":".","_npmVersion":"2.1.16","_nodeVersion":"0.10.25","_npmUser":{"name":"71104","email":"a71104@gmail.com"},"maintainers":[{"name":"71104","email":"a71104@gmail.com"}],"dist":{"shasum":"888d6a77a3351cc1a209204ef2ee1722093836cf","tarball":"https://registry.npmjs.org/rwlock/-/rwlock-5.0.0.tgz","integrity":"sha512-XgzRqLMfCcm9QfZuPav9cV3Xin5TRcIlp4X/SH3CvB+x5D2AakdlEepfJKDd8ByncvfpcxNWdRZVUl38PS6ZJg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBeiBd3xBeiqEkurEqunifjeYuD1YdLtabHh7Us2TudVAiEAlEplKvyN4Qdj5nI2AR6eiSGJ7LjpUVClqtRyBht9oQk="}]}}},"readme":"rwlock\n======\n\nAsynchronous read/write lock implementation for Node.js.\n\nMain rules:\n- there may be zero or more readers at a time,\n- there may be only one writer at a time,\n- there may be no writer if there are one or more readers already.\n\nInstallation\n------------\n\nIt's on [npmjs](https://npmjs.org/package/rwlock):\n\n```bash\n$ npm install rwlock\n```\n\nBasic usage\n-----------\n\nRequiring the package, creating an instance:\n\n```javascript\nvar ReadWriteLock = require('rwlock');\n\nvar lock = new ReadWriteLock();\n```\n\nAcquiring a read lock:\n\n```javascript\nlock.readLock(function (release) {\n\t// do stuff\n\n\trelease();\n});\n```\n\nAcquiring a write lock:\n\n```javascript\nlock.writeLock(function (release) {\n\t// do stuff\n\n\trelease();\n});\n```\n\nLocks can be released later:\n\n```javascript\nlock.readLock(function (release) {\n\t// not ready to release yet\n\n\tsetTimeout(function () {\n\t\t// ok, now I'm ready\n\t\trelease();\n\t}, 1000);\n});\n```\n\nUpgrading to a write lock\n-------------------------\n\nReadWriteLock does not explicitly support upgrading but you can take advantage of the asynchronous-ness:\n\n```javascript\nlock.readLock(function (release) {\n\t// read stuff here\n\n\t// ok, I now realize I need to write\n\n\t// this will be queued\n\tlock.writeLock(function (release) {\n\t\t// you can write here\n\n\t\trelease();\n\n\t\t// everything is now released.\n\t});\n\n\t// release the read lock, this will activate the writer\n\trelease();\n});\n```\n\nDowngrading to a read lock\n--------------------------\n\nSimilar to upgrading:\n\n```javascript\nlock.writeLock(function (release) {\n\tlock.readLock(function (release) {\n\t\t// ...\n\t\trelease();\n\t});\n\trelease();\n});\n```\n\nKeys\n----\n\nEvery ReadWriteLock instance allows you to work on a virtually unlimited number of completely independent read/write locks.\n\nLocks are identified by names called \"keys\". Every exposed method has an optional \"key\" first argument indicating the lock to work on; if you don't specify a key, the default lock is used.\n\nExample:\n\n```javascript\nlock.writeLock('lock1', function (release) {\n\tconsole.log('writing 1...');\n\tlock.writeLock('lock2', function (release) {\n\t\tconsole.log('writing 2...');\n\t\trelease();\n\t\tconsole.log('done 2.');\n\t});\n\trelease();\n\tconsole.log('done 1.');\n});\n```\n\nThe previous example logs:\n\n```\nwriting 1...\nwriting 2...\ndone 2.\ndone 1.\n```\n\n[async](https://npmjs.org/package/async) compatibility\n------------------------------------------------------\n\nThe ReadWriteLock class does not return errors to your callbacks, but many APIs in Node do. The `async` module uses that as a convention: callbacks usually receive two arguments, a possibly `null` error object and the actual result in case there is no error.\n\nTo aid `async` compatibility, ReadWriteLock sends `null` errors if you specify the `async` flag like in the following example:\n\n```javascript\nlock.async.readLock(function (error, release) {\n\t// no need to check on error, it will always be null\n\n\t// do stuff here\n\n\trelease();\n});\n```\n\nYou can use `rwlock` and `async` together like in this example:\n\n```javascript\nvar releaseLock = null;\n\nasync.waterfall([function (next) {\n\tlock.async.writeLock(next);\n}, function (release, next) {\n\treleaseLock = release;\n\tfs.writeFile('file', 'content', next);\n}, function (next) {\n\treleaseLock();\n\tnext(null);\n}], function (error) {\n\tif (error) {\n\t\tif (releaseLock) {\n\t\t\treleaseLock();\n\t\t}\n\t\tconsole.dir(error);\n\t} else {\n\t\tconsole.log('done.');\n\t}\n});\n```\n\nBuilding from source and testing\n--------------------------------\n\nYou don't need this, but in case you want:\n\n```bash\n$ sudo npm install -g grunt-cli\n$ cd\n$ git clone https://github.com/71104/rwlock.git\n$ cd rwlock\n$ npm install\n$ grunt all\n```\n\nThe following folders will be generated:\n- **lib**, containing the minified ReadWriteLock class to `require` in Node.js;\n- **doc**, containing the API reference documentation in HTML format.\n\nLicense\n-------\n\nMIT. Copyright 2013 Alberto La Rocca\n","maintainers":[{"name":"71104","email":"a71104@gmail.com"}],"time":{"modified":"2022-06-26T14:58:32.917Z","created":"2013-02-14T21:53:16.429Z","1.0.0":"2013-02-14T21:53:19.446Z","1.0.1":"2013-02-14T21:54:57.012Z","2.0.0":"2013-02-14T23:33:20.013Z","2.1.0":"2013-02-15T00:05:33.910Z","2.1.1":"2013-02-17T01:37:09.906Z","2.1.2":"2013-03-04T00:44:19.598Z","3.0.0":"2013-12-23T09:56:46.875Z","3.2.0":"2013-12-24T18:24:43.047Z","4.0.0":"2013-12-29T11:04:51.392Z","5.0.0":"2015-01-16T12:34:30.850Z"},"author":{"name":"Alberto La Rocca","email":"a71104@gmail.com"},"repository":{"type":"git","url":"https://github.com/71104/rwlock.git"},"homepage":"http://71104.github.io/rwlock","contributors":[{"name":"Alberto La Rocca","email":"a71104@gmail.com"},{"name":"Christian Lerrahn","email":"git@penpal4u.net"}],"bugs":{"url":"https://github.com/71104/rwlock/issues"},"license":"MIT","readmeFilename":"README.md","users":{"floby":true,"fedor":true,"mbucalo":true,"dzhou777":true}}