New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

param-mutex

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

param-mutex

ParamMutex

latest
npmnpm
Version
0.0.3
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

ParamMutex

GitHub

Mutex Library is a JavaScript library for managing mutex operations that are parameterized. This library is designed to address concurrency issues and prevent race conditions when accessing specific resources. Mutex is particularly useful for organizing and synchronizing asynchronous operations.

Table of Contents

  • ParamMutex

Demo

Mutex Library Demo

Installation

npm install param-mutex

Usage

An example scenario of using the Mutex library:

const {Mutex} = require('param-mutex')
const mutex = new Mutex('EXAMPLE_CHANNEL')

const decreaseAmountFromWallet = async (userId, amount) => {
    const { release } = await mutex.lock([userId], ['userId']);

    try {
        const walletTotal = await getWallet(userId);

        if (walletTotal >= amount) {
            await updateWallet(userId, -1 * amount);
        } else {
            throw new Error("Wallet amount is not enough");
        }

        release();

        return 1;
    } catch (e) {
        release();
        return 0;
    }
}

License

This project is licensed under the terms of the MIT License

FAQs

Package last updated on 22 Oct 2023

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