2.0.12 • Published 4 years ago

@everseenflash/lock v2.0.12

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

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

    1. maxLockDepth
      • type: number
      • default: 1
  • lock

    Returns promise of unlock function or wait and reject error when timeout.

    1. timeout
      • type: number
  • 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.

    1. maxLockDepth
      • type: number

Maintainer

everseenflash

2.0.12

4 years ago

2.0.11

4 years ago

2.0.10

4 years ago

2.0.9

4 years ago

2.0.8

4 years ago

2.0.7

4 years ago

2.0.6

4 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago