travix-lock-manager
In-memory lock manager for NodeJs helping to serialize access to a set of hierarchically organized resources with various levels of exclusivity.
Supports transactional semantics and can be easily persisted/distributed. Does not detect deadlocks.
See more information about lock managers on Wikipedia.
Installation
Install it via npm:
$ npm install --save travix-lock-manager
Usage
const CR CW EX NL PR PW = LockManager; const manager = console console; await manager;// Acquired: Lock of "resource" for "Exclusive"await manager;// Released: Lock of "resource" for "Exclusive" await manager;// Acquired: Lock of "resource" by "owner1" for "Protected Write"await manager;// Error: Some requested locks cannot be acquiredawait manager;// Acquired: Lock of "resource" by "owner2" for "Concurrent Read"await manager;// Acquired: Lock of "resource/a" by "owner3" for "Null" Lock of "resource/b" by "owner3" for "Null"await manager;// Released: Lock of "resource/a" by "owner3" for "Null" Lock of "resource/b" by "owner3" for "Null" managerkeys;// [ '', 'resource' ]managerlocks;/*[ Lock { key: '', mode: 4, owner: 'owner1' }, Lock { key: '', mode: 2, owner: 'owner2' }, Lock { key: 'resource', mode: 16, owner: 'owner1' }, Lock { key: 'resource', mode: 2, owner: 'owner2' }]*/ manager;// 'Concurrent Write' manager;/*Set { Lock { key: 'resource', mode: 16, owner: 'owner1' }, Lock { key: 'resource', mode: 2, owner: 'owner2' }}*/
Scripts
To run linting of source code and unit tests:
$ npm run lint
To run unit tests and generate test coverage report:
$ npm run test
Use NodeJs version 7.5 or higher to run this script because it relies on native support of async/await.
To generate documentation files:
$ npm run doc
Use NodeJs version 7.5 or higher to run this script because it relies on native support of async/await.
License
MIT © Travix International