Skip to content

Repository files navigation

semaphore

Semaphore for TypeScript/JavaScript.

npmjs Language: TypeScript Prettier eslint Code Style: Google

A Semaphore implementation clone of Python's asyncio.Semaphore.

A semaphore manages an internal counter which is decremented by each acquire() call and incremented by each release() call. The counter can never go below zero; when acquire() finds that it is zero, it blocks, waiting until some other thread calls release().

As JavaScript does not support context managers, you will need to wrap your function with the run() method.

const semaphore = new Semaphore(10);
async function myFunction() {
  // some async operation
  return 'Done';
}
const result = await semaphore.run(() => myFunction());
console.log(result); // prints "Done"

About

Semaphore for TypeScript/JavaScript

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages