padlocker
v0.0.1
Published
Simple OS-wide generic locking for node.js on Linux using abstract sockets
Downloads
2
Readme
Description
Simple OS-wide generic locking for node.js on Linux using abstract sockets. The use of abstract sockets allows for automatic unlocking when the process exits.
Requirements
Linux
- For node compiled with its bundled library dependencies
- node v21.6.2+
- node v22.0.0+
- For node compiled against shared library dependencies
- node v21.0.0+ and libuv v1.48.0+
- For node compiled with its bundled library dependencies
Installation
npm install padlocker
Examples
Lock and unlock
const PadLocker = require('padlocker');
const locker = new PadLocker('foo.bar.baz.lock');
(async() => {
await locker.lock();
// Do something
await locker.unlock();
})();
API
require('padlocker')
returns the PadLocker constructor.
PadLocker
PadLocker properties
- name - string - The name originally passed in to the constructor.
PadLocker methods
(constructor)(< string >name) - Creates and returns a new PadLocker instance.
lock([< integer >retries[, < integer >retryDelay]]) - Promise - Attempts to acquire the lock.
retries
if defined, must be a positive integer orInfinity
that represents how many attempts to make after the first try if unsuccessful (Default:Infinity
).retryDelay
if defined, must be a positive integer representing how many milliseconds to wait between retries (Default: 250ms).unlock() - Promise - Releases the lock.