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

ts-semaphore

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-semaphore

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

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
2.2K
10.18%
Maintainers
1
Weekly downloads
 
Created
Source

Semaphore

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

Installation

npm install --save ts-semaphore

Usage

const Semaphore = require('ts-semaphore')

const limit = new Semaphore(2)

// Only two requests will be sent at a time

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

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

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

API

new Semaphore(limit: number)

Creates a new Semaphore instance.

Semaphore#aquire(): Promise<void>

Aquire a lock from the semaphore, returns a Promise that resolves when the caller holds a lock.

Semaphore#release(): void

Release a lock back to the semaphore.

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

Aquire a lock from the semaphore, then run fn. If fn returns a Promise, wait for that promise to settle, then release the lock back to the semaphore.

Returns a Promise that will settle with the return value of fn.

FAQs

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