# @utilx/promise

> ## install

Latest version **0.0.4** (published 2019-04-12) · ISC license · 0 weekly downloads

## Install

```sh
npm install @utilx/promise
pnpm add @utilx/promise
yarn add @utilx/promise
bun add @utilx/promise
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2019-04-12 |
| First published | 2019-03-29 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 19 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | lteam |

## Links

- npm: https://www.npmjs.com/package/@utilx/promise
- Repository: https://github.com/edwinjhlee/promise-utils
- Homepage: https://github.com/edwinjhlee/promise-utils#readme
- Issues: https://github.com/edwinjhlee/promise-utils/issues
- npm.io page: https://npm.io/package/@utilx/promise

## Dependencies (2)

- [@utilx/iterator](https://npm.io/package/@utilx/iterator.md) latest
- [@utilx/semantic](https://npm.io/package/@utilx/semantic.md) latest

## Recent versions

- 0.0.4 (latest) — 2019-04-12
- 0.0.3 — 2019-04-05
- 0.0.2 — 2019-04-05
- 0.0.1 — 2019-04-04
- 0.0.0 — 2019-03-29

## README

# promise-utils

## install

```bash
npm install @utilx/promise --save
```


## 功能


### sleep函数，以及可中断

我可以提供一个 naive版本的

```typescript
const p = sleep(3000)
setTimeout(() => p.interrupt(), 1000)
await p // one second it will be interrupted
```

### TimeoutPromise

可以提供一个TimeoutPromise的设计，实现：

1. 可以定时关闭
2. 可以interrupt

### BlockingQueue






## 为什么不做n2n队列

1. 生产者蜂拥而至，处于await状态，此时其实排在系统内部的队列，本质与我们放在队列排队，无性能区别
2. 多个生产者在等候，如果无队列化，一定会出现争抢，效率不高

因此 n2n 就用 `n->1` 以及 `1->n` 来模拟，避免性能

特性：

1. n个prodcuer，n个consumer
n个prodcuer会

1. 设置是否blocking
2. 传入函数，n个兑现
3. consumer.take


# 测试

采用长度为1的blockingqueue，非常容易重现死锁的问题

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