Skip to content

hbinhng/minimum-lock

Repository files navigation

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.

About

The only minimum async lock you need.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published