# node-parallel

> Parallel provide a simple way for management of parrallel async/sync call

Latest version **0.1.6** (published 2016-01-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-parallel
pnpm add node-parallel
yarn add node-parallel
bun add node-parallel
```

## 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.6 |
| Published | 2016-01-29 |
| First published | 2013-09-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | chemzqm@gmail.com |
| Maintainers | chemzqm |
| Keywords | parallel, async |

## Links

- npm: https://www.npmjs.com/package/node-parallel
- Repository: https://github.com/chemzqm/parallel
- Homepage: https://github.com/chemzqm/parallel#readme
- Issues: https://github.com/chemzqm/parallel/issues
- npm.io page: https://npm.io/package/node-parallel

## Dependencies (1)

- [next-tick](https://npm.io/package/next-tick.md) ~0.1.0

## 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.6 (latest) — 2016-01-29
- 0.1.5 — 2013-12-02
- 0.0.5 — 2013-10-30
- 0.0.4 — 2013-10-06
- 0.0.3 — 2013-09-30
- 0.0.2 — 2013-09-29
- 0.0.1 — 2013-09-29

## README

[![Build Status](https://secure.travis-ci.org/chemzqm/parallel.png)](http://travis-ci.org/chemzqm/parallel)
[![Coverage Status](https://coveralls.io/repos/chemzqm/parallel/badge.png?branch=master)](https://coveralls.io/r/chemzqm/parallel?branch=master)

# Parallel

Parallel provide a simple but powerful way for management of parallel async call.

Normally we use [async](https://github.com/caolan/async) or [promise](https://github.com/then/promise) for parallel async control.
They can resolve every kind of async control problem we get, but the problem is they've done too much and it's neither easy to remember the complicated APIs nor refactoring the code.

Consider [chemzqm/serial](https://github.com/chemzqm/serial) if you want to control serial callbacks, they have almost the same API.

## Installation

Via npm:

    npm install node-parallel

Via [component](https://github.com/component/component):

    component install chemzqm/parallel

## Features

* Unified error handling.
* Timeout support.
* Immediate finished when error occur.
* No magic on finished callback, just one function.

## Test on node and browser

You must have `component` installed for browser usage and `mocha`, `mocha-phantomjs` installed for testing.

``` bash
$ npm install -g component mocha mocha-phantomjs
$ git clone git@github.com:chemzqm/parallel.git
$ cd parallel && npm install
$ make
#run test on server side
$ make test 
#run test through phantomjs
$ make phantomjs 
```

## Example

```js
var parallel = require('parallel');
var fs = require('fs');

parallel()
  .timeout(3000)
  .add(function(done) {
    fs.readFile('package.json', 'utf8', done);
  })
  .add(function(done) {
    fs.readFile('index.js', 'utf8', done);
  })
  .done(function(err, results) {
    console.log(results[0]);
    console.log(results[1]);
  })
```

## API

### Parallel()

Init new Parallel instance.

### .timeout(Number)

Set the timeout to number `ms`, default is `10s`.

### .add(Function)

Add Function to parallel, the first argument is a callback function, it should be called with `error` as first argument and result you need as secound argument.

### .done(Function)

The callback function is called with `error` (null or undefined if not exist) and the result array when all the request get finished (or timeout reached).

**Note**, this function should only be called once.

## License

  MIT

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