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

jsemaphore

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsemaphore

Simple semaphore, just like semaphore in python.

latest
Source
npmnpm
Version
1.0.6
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

jsemaphore

Coverage Status Language grade: JavaScript

Setup

npm i jsemaphore

or

yarn add jsemaphore

Usage

// Simulate tasks that take 1 second
async function task(s: Semaphore) {
  await new Promise((resolve) => setTimeout(() => resolve(null), 1000));
  s.release();
}
// Concurrency = 10
const s = new Semaphore(10);

const tasks = new Array<Promise<void>>();

// For total 40 tasks
for (let i = 0; i < 40; i++) {
  await s.acquire();
  tasks.push(task(s));
}

await Promise.all(tasks); // The total cost time is about 4 seconds

Keywords

semaphore

FAQs

Package last updated on 19 Mar 2021

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