Socket
Socket
Sign inDemoInstall

@slimio/lock

Package Overview
Dependencies
Maintainers
4
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@slimio/lock

SlimIO Asynchronous Lock Handler


Version published
Weekly downloads
70
decreased by-19.54%
Maintainers
4
Weekly downloads
 
Created
Source

Lock

version Maintenance MIT dep size Known Vulnerabilities Build Status

SlimIO Asynchronous Handler Mutex "Like" Lock. This package has been created to easily lock parallel execution of JavaScript Asynchronous function.

Requirements

  • Node.js v12 or higher

Getting Started

This package is available in the Node Package Repository and can be easily installed with npm or yarn.

$ npm i @slimio/lock
# or
$ yarn add @slimio/lock

Usage example

const Lock = require("@slimio/lock");

const asyncLocker = new Lock({ maxConcurrent: 3 });

async function npmInstall() {
    const free = await asyncLocker.acquireOne();
    try {
        await new Promise((resolve) => setTimeout(resolve, 1000));
        console.log("npm install resolved!");
    }
    finally {
        free();
    }
}

// Run 3 per 3 methods
Promise.all([
    npmInstall(),
    npmInstall(),
    npmInstall(),
    npmInstall(),
    npmInstall()
]).then(() => console.log("all done!")).catch(console.error);

API

Properties

declare class Lock {
    public readonly max: number;
    public readonly running: number;
}

Methods

acquireOne(): Promise< () => void >
Create a new lock counter. Return a function that you need to execute to free the counter/lock.
freeOne(error?: Error): void
free an acquired lock (or do nothing if there is no lock acquired yet).
rejectAll(errorMessage?: string): void
Reject all promises and available locks. This will throw an Error for each called acquireOne. The default error is `Lock acquisition rejected!`.
reset(): void
Reset the Object (will reject if any locks or promises are detected active).

Dependencies

This project have no dependencies.

License

MIT

Keywords

FAQs

Package last updated on 14 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc