# drainer

> Queue and drain an array of functions in series

Latest version **0.2.1** (published 2014-01-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install drainer
pnpm add drainer
yarn add drainer
bun add drainer
```

## 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.2.1 |
| Published | 2014-01-28 |
| First published | 2013-12-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Scott Corgan |
| Maintainers | scottcorgan |
| Keywords | queue, drain, series, array, async |

## Links

- npm: https://www.npmjs.com/package/drainer
- Repository: https://github.com/scottcorgan/drainer
- Issues: https://github.com/scottcorgan/drainer/issues
- npm.io page: https://npm.io/package/drainer

## Dependencies (1)

- [as-array](https://npm.io/package/as-array.md) ~0.1.1

## 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.2.1 (latest) — 2014-01-28
- 0.2.0 — 2014-01-28
- 0.1.0 — 2013-12-03

## README

# drainer

Queue and drain an array of functions in series.

## Install

```
npm install drainer --save
```

## Usage

```js
var drainer = require('drainer');

drainer([
  function (next) {
    next();
  },
  function (next) {
    next(null, 'some value');
  },
  function (arg1, next) {
    // arg1 == 'some value'
    next(null, 'final value');
  }
], function (err, finalValue) {
  // finalValue == 'final value';
});
```

### Handling Errors

Each function in the array recieves a callback, `next()`, to call when done. If only one argument is passed into that callback, it will assume that it is an error, exit the chain, and call the final callback with the error.

### Default Arguments

If you have arguments that you want to pass to each method without explicitly passing them each method, you can easily do that like this:

```js
var drainer = require('drainer');
var drain = drainer([
  function (defaultArg1, defaultArg2, next) {
    next();
  },
  function (defaultArg1, defaultArg2, next) {
    next();
  }
]);

drainer('defaultArg1', 'defaultArg2', function (err, defaultArg1, defaultArg2) {
  
});
```

### Passing Arguments from Method to Method

If you call the `next()` callback in the queued function with the first argument as `null`, any argument following will be passed to the next function in the queue.

The final callback will recieve any values passed from the last function in the function queue.

## Run Tests

```
npm install
npm test
```

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