{"_id":"schlock","_rev":"12-06a6dc85fc28696f8754e1fb23661521","name":"schlock","description":"Poorly-crafted in-process lock broker","dist-tags":{"latest":"0.2.1"},"versions":{"0.1.0":{"name":"schlock","description":"Poorly-crafted in-process lock broker","homepage":"http://github.com/e14n/schlock","version":"0.1.0","keywords":["schlock","lock","synchronization","sync","mutex","readlock","writelock","read-write","producer","consumer"],"engines":{"node":"0.8.x"},"author":{"name":"Evan Prodromou","email":"evan@e14n.com"},"scripts":{"test":"vows -i test/*-test.js"},"main":"./lib/schlock.js","directories":{"lib":"./lib/"},"devDependencies":{"vows":"0.6.x","step":"0.0.x"},"dependencies":{},"repository":{"type":"git","url":"git://github.com/e14n/schlock.git"},"licenses":[{"type":"Apache 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0.html"}],"_id":"schlock@0.1.0","dist":{"shasum":"556d769d2312e4f5db80d62c87b84b2733a42b5e","tarball":"https://registry.npmjs.org/schlock/-/schlock-0.1.0.tgz","integrity":"sha512-n3hbrQpMIIaGZ1M9NiMHuCLBLHlf1pkghBU+el+mqb6+dxrmVknnp+LE0TstwkJCGUvZa5MwM728NWIhCEJX5w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDqk8wXAssor9wdfbZlJWqsaGobj30EglbKUtzFIOFJygIhANLDUimbc1IP5ZjhDTG8QsC6VKNMrqFz6k7L4u1lTPjr"}]},"_npmVersion":"1.1.65","_npmUser":{"name":"evanp","email":"evan@status.net"},"maintainers":[{"name":"evanp","email":"evan@status.net"}]},"0.1.1":{"name":"schlock","description":"Poorly-crafted in-process lock broker","homepage":"http://github.com/e14n/schlock","version":"0.1.1","keywords":["schlock","lock","synchronization","sync","mutex","readlock","writelock","read-write","producer","consumer"],"engines":{"node":"0.8.x"},"author":{"name":"Evan Prodromou","email":"evan@e14n.com"},"scripts":{"test":"vows -i test/*-test.js"},"main":"./lib/schlock.js","directories":{"lib":"./lib/"},"devDependencies":{"vows":"0.6.x","step":"0.0.x"},"dependencies":{},"repository":{"type":"git","url":"git://github.com/e14n/schlock.git"},"licenses":[{"type":"Apache 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0.html"}],"_id":"schlock@0.1.1","dist":{"shasum":"19c3eb0c497dffbdd15ca4c54618c514ac43efb3","tarball":"https://registry.npmjs.org/schlock/-/schlock-0.1.1.tgz","integrity":"sha512-CtkE56x7BaZpFXIiiqd2OuCnY7ug+MmXvpskdU7xmwwkwStx4CFLo5K30qnJfN2Rn596FD1PX1NvoQyPuXXqew==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCpb6Dg3qj8FaZAB4ETn9dnEQtM+bZ9v1hRadFMQc6DtgIgBl5qLXyiMEvicTEjbE+Wl5mMf7o6lCPWwNq5gvTXQCw="}]},"_npmVersion":"1.1.63","_npmUser":{"name":"evanp","email":"evan@status.net"},"maintainers":[{"name":"evanp","email":"evan@status.net"}]},"0.2.0":{"name":"schlock","description":"Poorly-crafted in-process lock broker","homepage":"http://github.com/e14n/schlock","version":"0.2.0","keywords":["schlock","lock","synchronization","sync","mutex","readlock","writelock","read-write","producer","consumer"],"engines":{"node":"0.8.x"},"author":{"name":"Evan Prodromou","email":"evan@e14n.com"},"scripts":{"test":"vows -i test/*-test.js"},"main":"./lib/schlock.js","directories":{"lib":"./lib/"},"devDependencies":{"vows":"0.6.x","step":"0.0.x","bunyan":"0.14.x"},"dependencies":{},"repository":{"type":"git","url":"git://github.com/e14n/schlock.git"},"licenses":[{"type":"Apache 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0.html"}],"_id":"schlock@0.2.0","dist":{"shasum":"492c13c1248b551aedf7b7e45a9ce80fcba74096","tarball":"https://registry.npmjs.org/schlock/-/schlock-0.2.0.tgz","integrity":"sha512-j1yrH2mzddwGOuQWfo5bieo2CyYmIe7N2lJlxSuIveAnFN5lBsekD6a4A2lGa3IV23VAzU/n+VJ5sO2LBtMoDw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGMjr1U9M8/m/zfNnnBX+ahcAv6RaoJrIvsvUcLcnzfRAiEAufNEGui11lukHw3gqzgKbVqY98fRG59FlKbT4TEk0Ww="}]},"_npmVersion":"1.1.63","_npmUser":{"name":"evanp","email":"evan@status.net"},"maintainers":[{"name":"evanp","email":"evan@status.net"}]},"0.2.1":{"name":"schlock","description":"Poorly-crafted in-process lock broker","homepage":"http://github.com/e14n/schlock","version":"0.2.1","keywords":["schlock","lock","synchronization","sync","mutex","readlock","writelock","read-write","producer","consumer"],"engines":{"node":">= 0.8.0"},"author":{"name":"Evan Prodromou","email":"evan@e14n.com"},"scripts":{"test":"vows -i test/*-test.js"},"main":"./lib/schlock.js","directories":{"lib":"./lib/"},"devDependencies":{"vows":"0.7.x","step":"0.0.x","bunyan":"0.19.x"},"dependencies":{},"repository":{"type":"git","url":"git://github.com/e14n/schlock.git"},"licenses":[{"type":"Apache 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0.html"}],"_id":"schlock@0.2.1","dist":{"shasum":"2a9aaeaa209a5422eadc5dfc005e2c2f15241f99","tarball":"https://registry.npmjs.org/schlock/-/schlock-0.2.1.tgz","integrity":"sha512-WPdq6XwvXgnzXCLpwT6zqJQvqFWMDS0+W8cnSFqxmulJCyaPlNH5dStBg26tq9RxJj7fPAsp7Tu627m/k8+Ucg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDW5m8Ye1ugd9S/yicVsVDj7G2bTRKbqs2h9KQbCKL4AAIgUxStGVvAxeUiGKQxV2uvu8awEtTEo9dEb+Nzi1A0aSY="}]},"_from":".","_npmVersion":"1.2.14","_npmUser":{"name":"evanp","email":"evan@e14n.com"},"maintainers":[{"name":"evanp","email":"evan@status.net"}]}},"readme":"Schlock\n-------\n\nThis is a poorly-crafted read-write lock system. It only works\nin-process, and doesn't lock things between processes.\n\nSee also:\n\n> http://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock\n\nLicense\n=======\n\nCopyright 2012, E14N Inc.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n> http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\nOverview\n========\n\nThe module exports a single constructor that I call `Schlock` but you might\nwant to call something smarter.\n\n    var Schlock = require(\"schlock\");\n    \nYou need to create an instance to use it. I guess you could do this if\nyou had multiple sets of resources (files and cache elements, say)\nthat might share the same name.\n\n    var fileSchlock = new Schlock();\n    var cacheSchlock = new Schlock();\n\n    // These won't block each other\n    \n    fileSchlock.writeLock(\"foo\", ...);\n    cacheSchlock.writeLock(\"foo\", ...);\n    \nOnce you have a schlock, you use the `readLock`, `writeLock`,\n`readUnlock`, `writeUnlock` methods to manage resources.\n\nRead-only access to resources is pretty straightforward.\n\n    var fname = \"/tmp/myfile.txt\";\n    \n    fileSchlock.readLock(fname, function(err) {\n        fs.readFile(fname, function(err, data) {\n            fileSchlock.readUnlock(fname, function(err) {\n            // do something with the data\n            });\n        });\n    });\n\nRead-write access is about the same:\n\n    var fname = \"/tmp/myfile.txt\";\n    \n    fileSchlock.writeLock(fname, function(err) {\n        fs.readFile(fname, function(err, data) {\n            var newData = modify(data);\n            fs.writeFile(fname, newData, function(err) {\n                fileSchlock.writeUnlock(fname, function(err) {\n                // do something with the data\n                });\n            });\n        });\n    });\n\nI use [step](https://npmjs.org/package/step) to organize async stuff\nso it'd look more like this for me:\n\n    var fname = \"/tmp/myfile.txt\";\n\n    Step(\n        function() {\n            fileSchlock.writeLock(fname, this);\n        },\n        function(err) {\n            if (err) throw err;\n            fs.readFile(fname, this);\n        },\n        function(err, data) {\n            if (err) throw err;\n            var newData = modify(data);\n            fs.writeFile(fname, newData, this);\n        },\n        function(err) {\n            if (err) throw err;\n            fileSchlock.writeUnlock(fname, this);\n        },\n        function(err) {\n            next(err);\n        }\n    );\n\n...which is a little less crazy.\n\nMultiple reads on the same resource can happen at the same time. Only\none write on the same resource can happen at one time, and no reads\ncan happen while the write is happening.\n\nWrites get precedence to prevent starvation.\n\nFilesystem\n==========\n\nI made this so I could do atomic-ish changes to files, but note that\nit doesn't do `flock()` or any other operating-system-level locking\nautomatically. You still have to do that yourself.\n\nAPI\n===\n\n* `new Schlock()`\n\nCreates a new `Schlock`. Doesn't pay attention to any parameters.\n\n* `readLock(name, callback)`\n\nLock the resource `name` for reading and call `callback`. The callback\ntakes a single parameter, an error.\n\nIf the resource is currently write-locked, the callback will be queued\nto run once the write lock is unlocked.\n\n* `readUnlock(name, callback)`\n\nUnlock the resource `name` for reading and call `callback`. The\ncallback takes a single parameter, an error.\n\n* `writeLock(name, callback)`\n\nLock the resource `name` for reading and call `callback`. The callback\ntakes a single parameter, an error.\n\nIf the resource is currently write-locked or read-locked, the callback\nwill be queued to run once the write lock is unlocked.\n\n* `writeUnlock(name, callback)`\n\nUnlock the resource `name` for writing and call `callback`. The\ncallback takes a single parameter, an error.\n","maintainers":[{"email":"evan@e14n.com","name":"evanp"}],"time":{"modified":"2022-06-26T16:33:23.104Z","created":"2012-11-05T16:43:33.236Z","0.1.0":"2012-11-05T16:43:34.175Z","0.1.1":"2012-11-05T19:09:05.148Z","0.2.0":"2012-11-06T20:20:45.570Z","0.2.1":"2013-03-15T11:18:45.217Z"},"author":{"name":"Evan Prodromou","email":"evan@e14n.com"},"repository":{"type":"git","url":"git://github.com/e14n/schlock.git"},"homepage":"http://github.com/e14n/schlock","keywords":["schlock","lock","synchronization","sync","mutex","readlock","writelock","read-write","producer","consumer"],"readmeFilename":"README.md"}