# await-blocker

> A simple promise of semaphore, timeout..

Latest version **0.0.3** (published 2022-08-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install await-blocker
pnpm add await-blocker
yarn add await-blocker
bun add await-blocker
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2022-08-22 |
| First published | 2022-08-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 16.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | chuyong |
| Maintainers | chuyong |
| Keywords | mutex, semaphore, timeout, promise, await, async, await-blockers |

## Links

- npm: https://www.npmjs.com/package/await-blocker
- Repository: https://github.com/CChuYong/await-blockers
- Homepage: https://github.com/CChuYong/await-blockers#readme
- Issues: https://github.com/CChuYong/await-blockers/issues
- npm.io page: https://npm.io/package/await-blocker

## Dependencies (1)

- [typescript](https://npm.io/package/typescript.md) ^4.7.4

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 0.0.3 (latest) — 2022-08-22
- 0.0.2 — 2022-08-21

## README

# await-blockers
 A simple typescript promise of semaphore, mutex, timeout.

## Semaphore
Supports promise with semaphore.  
Simply create Semaphore instance, and put critical sections between acquire() and release().  
parameter of Semaphore's constructor is max number of concurrent tasks.  
Context will blocked if concurrent task of semaphore is over max number until release() called.

### Example
```ts
import { Semaphore } from 'await-blockers';
const semaphore = new Semaphore(2);
async semaphoreUsage(){
    await semaphore.acquire();
    try{
        ///... Some Critical Section
    } finally{
        await semaphore.release();
    }
}
```

## Mutex
Supports promise with mutex.  
It equals to Semaphore(1). Only allows one concurrent task.  
Context will blocked until release() called.

### Example
```ts
import { Mutex } from 'await-blockers';
const mutex = new Mutex();
async mutexUsage(){
    await mutex.acquire();
    try{
        ///... Some Critical Section
    } finally{
        await mutex.release();
    }
}
```

## Timeout
Supports promise with timeout.  
Context will blocked until timeout elapsed.

### Example
```ts
import { waitFor } from 'await-blockers';
async timeOutUsage(){
    console.log("Waiting 1 seconds...");
    await waitFor(1000); //Will block context for 1 seconds..
    //... A Method which called after 1 seconds..
    console.log("Done!");
}
```

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