2.0.12 • Published 4 years ago
@everseenflash/lock v2.0.12
Lock
Simple lock utils. Require ECMAScript2015+ support.
Install
npm install @everseenflash/lock
Usage
const lock = new Lock(2);
const unlock1 = await lock.lock();
const unlock2 = await lock.lock();
setTimeout(unlock1, 1000);
await lock.lock(); //will wait until lock released
console.log(lock.isLocked());
console.log(lock.getLockDepth());
API
Lock
Lock with a customizable depth.
new Lock(maxLockDepth?)
Construct a lock and customize its max lock depth. Throws if maxLockDepth is not a number or is less than 1
maxLockDepth
- type:
number
- default:
1
- type:
lock
Returns promise of unlock function or wait and reject error when timeout.
timeout
- type:
number
- type:
isLocked()
Returns whether this lock is locked
getLockDepth()
Returns current lock depth
getMaxLockDepth()
Returns max lock depth
adjustMaxLockDepth(maxLockDepth)
Adjust max lock depth. Throws if maxLockDepth is not a number or is less than 1. Throws if is already locked.
maxLockDepth
- type:
number
- type: