# sparallel

> Super parallel function runner.

Latest version **1.0.3** (published 2017-11-09) · MIT license · 0 weekly downloads

## Install

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

## 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.0.3 |
| Published | 2017-11-09 |
| First published | 2016-03-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Sam Eaton |
| Maintainers | same |
| Keywords | function, parallel, async, asynchronous |

## Links

- npm: https://www.npmjs.com/package/sparallel
- Repository: https://github.com/samueleaton/sparallel
- Homepage: https://github.com/samueleaton/sparallel#readme
- Issues: https://github.com/samueleaton/sparallel/issues
- npm.io page: https://npm.io/package/sparallel

## 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

- 1.0.3 (latest) — 2017-11-09
- 1.0.2 — 2016-12-10
- 1.0.1 — 2016-12-10
- 1.0.0 — 2016-05-31
- 0.0.4 — 2016-04-01
- 0.0.3 — 2016-03-31
- 0.0.2 — 2016-03-05
- 0.0.1 — 2016-03-05

## README

# Sparallel

Super parallel function runner.

Simply pass functions to `sparallel` and call the `done` (or `resolve`) callback when each finishes. Sparallel returns a promise so the `then` method takes a callback that will run after all other functions have called the `done` callback.

Sounds confusing, so here's an example:

``` javascript
import sparallel from 'sparallel';

sparallel(
    done => {
        console.log('code 1');
        done();
    },
    done => {
        console.log('code 2');
        done();
    },
    done => {
        console.log('code 3');
        done();
    }
).then(() => {
    console.log('all done.');
});
```

### The Best Part

The best part of sparallel is that you can pass an object to each `done` callback and all of the objects will be merged into a single object and passed to the `then` callback.

Example

``` javascript
sparallel(
    done => {
        setTimeout(function() {
            done({name: 'sam'});
        }, 1000);
    },
    done => {
        setTimeout(function() {
            done({color: 'blue'});
        }, 1100);
    },
    done => {
        setTimeout(function() {
            done({fat: 'probably not'});
        }, 5);
    }
).then(resObj => {
    console.log(resObj); // {name: 'sam', color: 'blue', fat: 'probably not'}
});
```

### Error Handling

The second parameter to each function is an optional error handler.

Example

``` javascript
sparallel(
    resolve => {
        setTimeout(function() {
            resolve({name: 'sam'});
        }, 1000);
    },
    (resolve, error) => {
        setTimeout(function() {
            error('i failed :(');
        }, 1100);
    },
    resolve => {
        setTimeout(function() {
            resolve({fat: 'probably not'});
        }, 5);
    }
)
// will NOT run
.then(resObj => {
    console.log(resObj); // {name: 'sam', fat: 'probably not'}
})
// will run
.catch(error => {
    console.log(error); // "i failed :("
});
```

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