# parallel-js

> Run tasks in parallel or one after another

Latest version **1.1.0** (published 2014-11-05) · MIT license · 0 weekly downloads

## Install

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

## 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.1.0 |
| Published | 2014-11-05 |
| First published | 2014-05-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | x25 |
| Maintainers | x25 |
| Keywords | parallel, async, concurrent, queue |

## Links

- npm: https://www.npmjs.com/package/parallel-js
- Repository: https://github.com/x25/parallel-js
- Issues: https://github.com/x25/parallel-js/issues
- npm.io page: https://npm.io/package/parallel-js

## 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) — 2014-11-05
- 1.0.9 — 2014-05-26
- 1.0.8 — 2014-05-26
- 1.0.2 — 2014-05-25
- 0.0.2 — 2014-05-24
- 0.0.1 — 2014-05-24

## README

parallel-js [![](https://travis-ci.org/x25/parallel-js.png)](https://travis-ci.org/x25/parallel-js) [![](https://coveralls.io/repos/x25/parallel-js/badge.png)](https://coveralls.io/r/x25/parallel-js)
===========

Run functions and processes in parallel or one after another.

```bash
$ npm install parallel-js
```

## Usage

Example: resizing huge images in parallel using ImageMagick and child process.

```js
var Processor = require('parallel-js').Processor;

var task = function (next, command, args) {

	var child = require('child_process').spawn(command, args);

	child.on('close', function (code) {

		console.log(new Date(), command, args, 'finished with code', code);

		next(code);
	});
};

var maxProcess = 2;
var numRetries = 1;

var parallel = new Processor(task, maxProcess, numRetries);

//These tasks are processed in parallel (maxProcess=2)
parallel.run('convert', ['1.jpg', '-resize', '50%', '1.png']);
parallel.run('convert', ['2.jpg', '-resize', '50%', '2.png']);

//After completing one of the tasks the next task will be launched
parallel.run('convert', ['3.jpg', '-resize', '50%', '3.png']);

// Task ended with an error will be repeated 1 more time (numRetries=1)
parallel.run('convert', ['missing.jpg', '-resize', '50%', 'missing.png']);
```

Output:

```
[17:13:52] "convert 1.jpg -resize 50% 1.png" finished with code 0
[17:13:52] "convert 2.jpg -resize 50% 2.png" finished with code 0
[17:13:53] "convert missing.jpg,-resize 50% missing.png" finished with code 1
[17:13:53] "convert missing.jpg,-resize,50% missing.png" finished with code 1
[17:13:58] "convert 3.jpg -resize 50% 3.png" finished with code 0
```

## Tests

```sh
$ npm test
```

## License

MIT

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