minimum-lock
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i minimum-lock

Weekly Downloads

1

Version

1.0.1

License

GPL-3.0-or-later

Unpacked Size

3.88 kB

Total Files

6

Last publish

Collaborators

  • boong