1.0.0 • Published 3 years ago

@slimio/lock v1.0.0

Weekly downloads
34
License
MIT
Repository
github
Last release
3 years ago

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

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

Dependencies

This project have no dependencies.

License

MIT

1.0.0

3 years ago

0.5.0

4 years ago

0.4.0

4 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago