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

ts-mutex

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-mutex

A very simple Mutex, with an easy to use API and excellent TypeScript typings.

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
52
-32.47%
Maintainers
1
Weekly downloads
 
Created
Source

Mutex

A very simple Mutex, with an easy to use API and excellent TypeScript typings.

Installation

npm install --save ts-mutex

Usage

import Mutex = require('mutex')

const lock = new Mutex()

// Only one request will be sent at a time

lock.use(async () => {
  console.log((await fetch('https://google.com/')).code)
})

lock.use(async () => {
  console.log((await fetch('https://twitter.com/')).code)
})

lock.use(async () => {
  console.log((await fetch('https://facebook.com/')).code)
})

API

new Mutex()

Creates a new Mutex instance.

Mutex#locked: boolean

Whether the mutex is currently locked or not.

Mutex#use<T> (fn: () => T | PromiseLike<T>): Promise<T>

Aquire the lock, then execute (possibly async) function fn, and finally release the lock. Returns a Promise of whatever the function fn returns.

The lock will be released even if fn throws or returns a rejected Promise. In this case, the Promise returned will also be rejected with that error.

FAQs

Package last updated on 04 Jun 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