# async-queue-chain

> [![npm](https://img.shields.io/npm/v/async-queue-chain?style=for-the-badge)](https://www.npmjs.com/package/async-queue-chain) [![npm bundle size](https://img.shields.io/bundlephobia/minzip/async-queue-chain?style=for-the-badge)](https://bundlephobia.com/r

Latest version **1.1.0** (published 2022-12-03) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2022-12-03 |
| First published | 2022-04-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Kirill Romanov |
| Maintainers | djaler |
| Keywords | async, queue |

## Links

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

## 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.1.0 (latest) — 2022-12-03
- 1.0.2 — 2022-04-13
- 1.0.1 — 2022-04-13
- 1.0.0 — 2022-04-12

## README

[![npm](https://img.shields.io/npm/v/async-queue-chain?style=for-the-badge)](https://www.npmjs.com/package/async-queue-chain)
[![npm bundle size](https://img.shields.io/bundlephobia/minzip/async-queue-chain?style=for-the-badge)](https://bundlephobia.com/result?p=async-queue-chain)

# Async Queue Chain

> A tiny utility to chain async functions in queue and run them sequentially.

## Install

```sh
npm install --save async-queue-chain
```
or
```sh
yarn add async-queue-chain
```
or
```sh
pnpm install async-queue-chain
```

## Usage

Simply create a queue with fixed number of tasks and run them sequentially.

```js
await createAsyncQueue()
    .add(async () => {
        // do something
    })
    .add(async () => {
        // do something
    })
    .run();
```

Or create a queue, then dynamically add a task from event handler and run queue.

```js
const queue = createAsyncQueue();

document.addEventListener('click', () => {
    queue.add(async () => {
        // do something
    });
    queue.run();
});
```

No matter how fast you'll add tasks, how long it will take to run a task, the queue will run them sequentially.
Also, queue will simply skip a "run" call if it's already running.

If a task returns a value, it will be passed to the next task. In such case, you'll need to provide initial value for
the first task in run method.

```js
const queue = createAsyncQueue();
for (let i = 0; i < 10; i++) {
    queue.add(async (value) => {
        // do something

        return value + 1;
    });
}
const result = await queue.run(0);
console.log(result); // 10
```

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