🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

m-padlock

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

m-padlock

Promise based javascript mutexes

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

m-padlock

Create a Promise based mutex

Installing

npm install m-padlock --save

Examples

Use cases for mutexes are slim in nodejs, given the single threaded async nature. Very rarely there are cases such as concurrent transactions that would be preferable to run one at a time.

const Mutex = require('m-padlock');
const mutex = new Mutex();


// Using async/await (Node v8+)
const unlock = await mutex.lock();
await postgres.transaction(trx => {
  // do work
});
unlock();

// Using promises
mutex.lock()
  .then(unlock => {
    return postgres.transaction(trx => {
      // do work
    })
    .then(() => unlock());
  });

Tests

From the m-padlock root directory run:

npm install
npm run test

This will generate a coverage report inside the root directory in a new directory called coverage

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Keywords

mutex

FAQs

Package last updated on 07 May 2018

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