1.0.1 • Published 5 months ago

minimum-lock v1.0.1

Weekly downloads
-
License
GPL-3.0-or-later
Repository
github
Last release
5 months ago

License: GPL v3 Coverage Status

Minimum lock

This package provides a bare minimum tool for "locking" resources.

How to use it?

Installation

You can install the library into your project via npm:

npm install minimum-lock

This package does not have any dependencies.

Usage

Again, this tool is bare minimum, it does not provide any fancy interface, just a class to create an object which can be locked and released.

import { Lock } from 'minimum-lock';

async function doSomethingWithLock(lock) {
  const release = await lock.acquire();
  
  doSomethingMustBeSequential();
  
  release();
}

async function doSomething() {
  ...
  
  const lock = new Lock();
  
  doSomethingWithLock(lock);
  doSomethingWithLock(lock);
}

⚠️ The acquire method returns a release callback, if you forget to call this release callback, the lock is locked forever.

1.0.1

5 months ago

1.0.0

5 months ago