https://github.com/dutu/semaphore
A simple ES6 semaphore implementation
https://github.com/dutu/semaphore
Last synced: 8 months ago
JSON representation
A simple ES6 semaphore implementation
- Host: GitHub
- URL: https://github.com/dutu/semaphore
- Owner: dutu
- Created: 2023-06-12T09:03:24.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-06-12T10:11:45.000Z (about 3 years ago)
- Last Synced: 2025-01-16T11:59:28.654Z (over 1 year ago)
- Language: JavaScript
- Size: 7.29 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README

# semaphore
A simple ES6 semaphore implementation for managing concurrent access to a resource.
## Installation
```bash
yarn add @dutu/semaphore@github:dutu/semaphore
```
## Usage
```js
import Semaphore from '@dutu/semaphore'
const sem = new Semaphore()
async function task() {
console.log("Waiting for semaphore...")
await sem.wait()
console.log("Semaphore is green. Continuing task...")
}
sem.red()
task()
setTimeout(() => {
sem.green()
}, 5000)
```
See [the API documentation](https://dutu.github.io/semaphore/) for more details on how to use it.