__ ____ ____
____/ /__ ____ _____/ / /_ ____ / / /_
/ __ / _ \/ __ `/ __ / __ \/ __ \/ / __/
/ /_/ / __/ /_/ / /_/ / /_/ / /_/ / / /_
\__,_/\___/\__,_/\__,_/_.___/\____/_/\__/
Description
Having locks in async world is not so straight-forward as it may look like. Everything can work fine, but when exception will be thrown in your app - locks may stay active until script's termination.
Here comes deadbolt to save all us:
var deadbolt = ; deadbolt;
Or just wrap callbacks without setting lock:
{ callback = deadbolt; ;};
How does it work?
It's using v8's MakeWeak
black magic. When lock
becomes weak (not referenced in your program) -
autorelease
callback will be called.
Basically, if you forgot to call your callback
- deadbolt will do it for you.
API
Full documentation is available here.
deadbolt.create
deadbolt;
Creates Deadbolt
's instance, default storage type is memory
(redis
is
available for multi-process locks).
Possible options for redis storage are:
"host": "localhost" "port": 6379 "password": "redis password, if you have any" "ttl": 300 // time-to-live for locks (see EXPIRE command for redis) "prefix": "deadbolt" // all used keys will be prefixed
deadbolt.lock
// for global instance with memory storagedeadbolt; // For some manually created instanceDeadbolt#;
Creates lock, info
will be shown in error passed to autorelease
callback.
lock.release, lock.autorelease
deadbolt;
Installation
If you're using npm:
npm install deadbolt
From source:
git clone git://github.com/indutny/deadbolt.gitcd deadbolt./configure && make
LICENSE
(The MIT License)
Copyright (c) 2011 Fedor Indutny fedor@indutny.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.