semaphore-throughput
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

semaphore

Example usage

Print i love flan one per second, ten times

import Semaphore from 'semaphore-throughput';

let max_concurrency = 1; // Concurrency limit
let max_throughput = 1; // Process rate per second
let sem = new Semaphore(max_concurrency, max_throughput);

for (let i = 0; i < 10; i++) {
    sem.wait().then(() =>{
        console.log("i love flan");
        sem.release();
    });
}

for (let i = 0; i < 10; i++) {
    new Promise(async function () {
        await sem.wait();
        console.log("i love flan");
        sem.release();
    })    
}

Instalation

npm i semaphore-throughput --save

Package Sidebar

Install

npm i semaphore-throughput

Weekly Downloads

1

Version

1.0.2

License

ISC

Unpacked Size

12.6 kB

Total Files

7

Last publish

Collaborators

  • robertgeb