1.0.6 • Published 3 years ago

jsemaphore v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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
1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago