# orderly-queue

> Implementation of a promise-based FIFO queuing system using ES2017 async generators.

Latest version **0.1.10** (published 2017-01-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install orderly-queue
pnpm add orderly-queue
yarn add orderly-queue
bun add orderly-queue
```

## 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.1.10 |
| Published | 2017-01-20 |
| First published | 2016-11-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Adam Timberlake |
| Maintainers | wildhoney |
| Keywords | queue, promise, tasks, task, sequence, enqueue, await, wait for, async, asynchronous |

## Links

- npm: https://www.npmjs.com/package/orderly-queue
- Repository: https://github.com/Wildhoney/OrderlyQueue
- Homepage: https://github.com/Wildhoney/OrderlyQueue#readme
- Issues: https://github.com/Wildhoney/OrderlyQueue/issues
- npm.io page: https://npm.io/package/orderly-queue

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@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

## Recent versions

- 0.1.10 (latest) — 2017-01-20
- 0.1.9 — 2017-01-19
- 0.1.8 — 2017-01-19
- 0.1.7 — 2016-11-17
- 0.1.6 — 2016-11-11
- 0.1.5 — 2016-11-11
- 0.1.4 — 2016-11-10
- 0.1.3 — 2016-11-10
- 0.1.1 — 2016-11-08
- 0.1.0 — 2016-11-07

## README

# Orderly Queue

![Bus Queue](/media/bus-queue.jpg)

> Implementation of a promise-based FIFO queuing system using ES2017 async generators.

![Travis](http://img.shields.io/travis/Wildhoney/OrderlyQueue.svg?style=flat-square)
&nbsp;
![npm](http://img.shields.io/npm/v/orderly-queue.svg?style=flat-square)
&nbsp;
![License MIT](http://img.shields.io/badge/License-MIT-lightgrey.svg?style=flat-square)

> **npm:** `npm i orderly-queue -S`<br />
> **Babel:** [`babel-plugin-syntax-async-generators`](https://www.npmjs.com/package/babel-plugin-syntax-async-generators)

* Takes a function that returns a promise (or `Promise.all`)
* Invokes the promise and `yield`s the eventual result
* Awaits the completion of the task before beginning the next
* Implements a pseudo-observable for `next` and `error`
* Passes the returned `props` along to the next task

# Usage

```javascript
import Queue from 'orderly-queue';

const queue = Queue({ value: ['Blueberries'], next: console.log });

queue.process(fruits => Promise.resolve([...fruits, 'Apples']));
queue.process(fruits => Promise.resolve([...fruits, 'Bananas']));
queue.process(fruits => Promise.resolve([...fruits, 'Raspberries']));

// > ['Blueberries']
// > ['Blueberries', 'Apples']
// > ['Blueberries', 'Apples', 'Bananas']
// > ['Blueberries', 'Apples', 'Bananas', 'Raspberries']
```

Each task will wait before the completion of the current task, meaning you can safely assume the order of `fruits` no matter how long it takes for a single task to complete.

## Errors

Any errors that are raised will be passed to the `error` function, however the items in the queue will continue to be invoked one-at-a-time passing in the `props` from the last successful invocation.

```javascript
import Queue from 'orderly-queue';

const queue = Queue({ value: ['Blueberries'], next: console.log, error: console.log });

queue.process(fruits => Promise.resolve([...fruits, 'Apples']));
queue.process(fruits => Promise.reject('Error: Fruitless...'));
queue.process(fruits => Promise.resolve([...fruits, 'Bananas']));
queue.process(fruits => Promise.resolve([...fruits, 'Raspberries']));

// > ['Blueberries']
// > ['Blueberries', 'Apples']
// > Error: Fruitless...
// > ['Blueberries', 'Apples', 'Bananas']
// > ['Blueberries', 'Apples', 'Bananas', 'Raspberries']
```

In cases where you wish to end the iterator early you can invoke the `abort` method &mdash; perhaps in response to an error being raised. Any queued tasks will not be run.

```javascript
const queue = Queue({ value: ['Blueberries'], next: console.log, error: console.log });

// ...

queue.abort();
```

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