# async-delay-queue

> Minimal ES7 async queue with dynamic delay between functions, with 0 dependencies.

Latest version **1.0.11** (published 2018-03-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install async-delay-queue
pnpm add async-delay-queue
yarn add async-delay-queue
bun add async-delay-queue
```

## 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.0.11 |
| Published | 2018-03-30 |
| First published | 2017-08-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 194.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Kaptard |
| Maintainers | kaptard |
| Keywords | queue, async, stack, timed, delay |

## Links

- npm: https://www.npmjs.com/package/async-delay-queue
- Repository: https://github.com/kaptard/async-delay-queue
- Homepage: https://github.com/kaptard/timed-queue#readme
- Issues: https://github.com/kaptard/timed-queue/issues
- npm.io page: https://npm.io/package/async-delay-queue

## 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

- 1.0.11 (latest) — 2018-03-30
- 1.0.9 — 2018-03-19
- 1.0.8 — 2018-03-19
- 1.0.7 — 2018-01-12
- 1.0.6 — 2017-10-17
- 1.0.5 — 2017-10-17
- 1.0.4 — 2017-08-23
- 1.0.3 — 2017-08-23
- 1.0.2 — 2017-08-23
- 1.0.1 — 2017-08-23
- 1.0.0 — 2017-08-23

## README

# async-delay-queue
Minimal ES7 async queue with dynamic delay between functions.

<br>

## Usage
```js
queue.delay(fn, delay, timer, add)
```
> Returns a promise resolving the return value of the given function.

| Argument | Description | Default |
|:------------- |:------------- |:------------- |
| fn | Function to delay. Supports promise/async functions. | None |
| delay | Delay between this function and the last one in ms. Required. | null |
| timer | Max time until the active promise is forcefully resolved to prevent the queue getting stuck. | null |
| add | Method with which the function is added to the queue stack. "unshift" to add to start, "push" to add to end of queue. | "push" |

<br>

## Example
Crawl Google.com and retry when hitting rate limits.
```js
const queue = require("async-delay-queue")
const request = require("request-promise") // for example purposes only

async crawl(url) {
  let res = await queue.delay(() => request(url), 100)

  // Hit rate limits? Put the same request at the start of the queue.
  // "unshift" to push at start, and increase delay to 10s.
  if (res.statusCode === 429) {
    res = await queue.delay(() => request(url), 10000, null, "unshift")
  }

  return res
}

// Crawls google.com 20 times with a 100ms delay between each request.
for (let i = 0; i < 20; i++) {
  crawl("http://google.com")
}
```

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