# @calebboyd/semaphore

> Simple promise based counting semaphore

Latest version **1.3.1** (published 2018-05-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install @calebboyd/semaphore
pnpm add @calebboyd/semaphore
yarn add @calebboyd/semaphore
bun add @calebboyd/semaphore
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.1 |
| Published | 2018-05-11 |
| First published | 2016-07-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Caleb Boyd |
| Maintainers | calebboyd |

## Links

- npm: https://www.npmjs.com/package/@calebboyd/semaphore
- npm.io page: https://npm.io/package/@calebboyd/semaphore

## Recent versions

- 1.3.1 (latest) — 2018-05-11
- 1.3.0 — 2018-05-11
- 1.2.0 — 2017-12-19
- 1.1.0 — 2017-12-15
- 1.0.4 — 2017-10-16
- 1.0.3 — 2016-07-10
- 1.0.2 — 2016-07-10
- 1.0.1 — 2016-07-10
- 1.0.0 — 2016-07-10

## README

## Semaphore

Naive resource management / concurrency primitive

`npm i @calebboyd/semaphore`

### Example
```javascript
import { Semaphore } from '@calebboyd/semaphore'
import { something } from './somewhere'

function doSomeWork () {
  const lock = new Semaphore(10)
  while(something.isTrue) {
    lock.acquire().then(x => () => {
      something.work().then(lock.release)
    })    
  }
}
```
The semaphore will only allow 10 locks to be aquired at a time. This limits the concurrency of the asyncronous function `something.work` to 10

#### API: 

```typescript
export class Semaphore {
  constructor (count: number) {}
  acquire(): Promise<void>
  release(): void
}
```

## License

MIT

---
_Source: https://npm.io/package/@calebboyd/semaphore · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
