# serial-promise

> run promises with timeout, in series

Latest version **0.0.3** (published 2018-07-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install serial-promise
pnpm add serial-promise
yarn add serial-promise
bun add serial-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.3 |
| Published | 2018-07-13 |
| First published | 2018-07-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | exoticknight |
| Maintainers | exoticknight |
| Keywords | promise, queue, serial, timeout |

## Links

- npm: https://www.npmjs.com/package/serial-promise
- Repository: https://github.com/exoticknight/SerialPromise
- Homepage: https://github.com/exoticknight/SerialPromise#readme
- Issues: https://github.com/exoticknight/SerialPromise/issues
- npm.io page: https://npm.io/package/serial-promise

## Alternatives

- [cron](https://npm.io/package/cron.md) — 4.9M weekly downloads
- [@vercel/queue](https://npm.io/package/@vercel/queue.md) — 731.6K weekly downloads
- [create-sonicjs](https://npm.io/package/create-sonicjs.md) — 1.6K weekly downloads
- [@exellix/jobs-api](https://npm.io/package/@exellix/jobs-api.md) — 941 weekly downloads
- [@forwardimpact/libskill](https://npm.io/package/@forwardimpact/libskill.md) — 575 weekly downloads

## Recent versions

- 0.0.3 (latest) — 2018-07-13
- 0.0.2 — 2018-07-12
- 0.0.1 — 2018-07-12

## README

# SerialPromise

run promises with timeout, in queue

> you can alse check [parallel-promise](https://www.npmjs.com/package/parallel-promise)

## Install

```bash
npm install queue-promise --save
```

## Usage

```javascript
import SerialPromise, { StatusCode } from 'serial-promise'

SerialPromise(
  [
    lastResult => {
      // lastResult equals null at first
      // return a promise that resolves in 100ms
    },
    lastResult => {
      // lastResult equals { status: StatusCode.RESOLVE, data:[your data] }
      // return a promise that resolves in 3000ms
    },
    lastResult => {
      // lastResult equals { status: StatusCode.TIMEOUT, timeout: 2000 }
      // return a promise that rejects in 100ms
    },
    lastResult => {
      // lastResult equals { status: StatusCode.REJECT, err:[error] }
      // return a promise that rejects in 3000ms
    },
  ],
  [1000, 2000, 1000, 2000],  // timeout for each promise, no timeout if undefined
  500,  // time delay between each promise, you can even use [500, 1000, 3000] to control
  (progress) => {
    // called whenever a promise's state is changed
    // progress == {
    //   total: 4,  total count of promise
    //   resolve: [],  array of the index of the resolved promises
    //   reject: [],  array of the index of the rejected promises
    //   timeout: [],  array of the index of the timeouted promise
    // }
  }
).then(rets => {
  // rets == [
  //   { status: StatusCode.RESOLVE, data:[your data] },
  //   { status: StatusCode.TIMEOUT, timeout: 2000 }
  //   { status: StatusCode.REJECT, err:[error] },
  //   { status: StatusCode.TIMEOUT, timeout: 2000 }
  // ]
})// NOTE that there is not .catch here
```

You can use async/await as well.

## StatusCode

| Status | StatusCode |
|---|---|
| RESOLVE | 0 |
| REJECT | 1 |
| TIMEOUT | -1 |

## Test

```bash
npm run test
```

## License

MIT

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