# @cjssdk/async

> Asynchronous tools.

Latest version **1.5.1** (published 2018-04-27) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @cjssdk/async
pnpm add @cjssdk/async
yarn add @cjssdk/async
bun add @cjssdk/async
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.5.1 |
| Published | 2018-04-27 |
| First published | 2018-04-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Stanislav Kalashnik |
| Maintainers | cjssdk |
| Keywords | commonjs, sdk, cjssdk, framework, async |

## Links

- npm: https://www.npmjs.com/package/@cjssdk/async
- Repository: https://github.com/cjssdk/async
- Homepage: https://github.com/cjssdk/async#readme
- Issues: https://github.com/cjssdk/async/issues
- npm.io page: https://npm.io/package/@cjssdk/async

## Alternatives

- [@sveltejs/kit](https://npm.io/package/@sveltejs/kit.md) — 2.2M weekly downloads
- [@tangle-network/brand](https://npm.io/package/@tangle-network/brand.md) — 10.0K weekly downloads
- [seneca](https://npm.io/package/seneca.md) — 7.4K weekly downloads
- [@bsb/base](https://npm.io/package/@bsb/base.md) — 7.2K weekly downloads
- [@modern-js/plugin-swc](https://npm.io/package/@modern-js/plugin-swc.md) — 3.4K weekly downloads

## Recent versions

- 1.5.1 (latest) — 2018-04-27

## README

Asynchronous tools
==================

[![build status](https://img.shields.io/travis/cjssdk/async.svg?style=flat-square)](https://travis-ci.org/cjssdk/async)
[![npm version](https://img.shields.io/npm/v/@cjssdk/async.svg?style=flat-square)](https://www.npmjs.com/package/@cjssdk/async)
[![dependencies status](https://img.shields.io/david/cjssdk/async.svg?style=flat-square)](https://david-dm.org/cjssdk/async)
[![devDependencies status](https://img.shields.io/david/dev/cjssdk/async.svg?style=flat-square)](https://david-dm.org/cjssdk/async?type=dev)
[![Gitter](https://img.shields.io/badge/gitter-join%20chat-blue.svg?style=flat-square)](https://gitter.im/DarkPark/cjssdk)
[![RunKit](https://img.shields.io/badge/RunKit-try-yellow.svg?style=flat-square)](https://npm.runkit.com/@cjssdk/async)
[![API](https://img.shields.io/badge/API-docs-orange.svg?style=flat-square)](https://cjssdk.github.io/async/)


Set of methods to synchronize asynchronous operations.


## Installation ##

```bash
npm install @cjssdk/async
```


## Usage ##

### parallel ###

Run the tasks array of functions in parallel, without waiting until the previous function has completed.
If any of the functions pass an error to its callback, the main callback is immediately called with the value of the error.
Once the tasks have completed, the results are passed to the final callback as an array and hash.
Task function name is used to name the corresponding hash-table values.
Task function can either use callback to specify error and result value or return result value immediately.

Online [example](https://runkit.com/darkpark/cjs-async-parallel):

```js
var parallel = require('@cjssdk/async/parallel'),
    taskList = [
        function ( callback ) {
            setTimeout(function () {
                callback(null, true);
            }, 10);
        },
        function ( callback ) {
            setTimeout(function () {
                callback(null, 256);
            }, 20);
        },
        function ( callback ) {
            setTimeout(function () {
                callback(null, '512');
            }, 0);
        },
        function () {
            return 32;
        }
    ];

parallel(taskList, function ( error, results ) {
    if ( !error ) {
        // results contains array of the given tasks execution results
        // [true, 256, '512', 32]
        console.log(results);
    }
});
```

### serial ###

Run the functions in the tasks array in series, each one running once the previous function has completed.
If any functions in the series pass an error to its callback, no more functions are run,
and callback is immediately called with the value of the error.
Otherwise, callback receives an array and hash of results when tasks have completed.
Task function name is used to name the corresponding hash-table values.
Task function can either use callback to specify error and result value or return result value immediately.

Online [example](https://runkit.com/darkpark/cjs-async-serial):

```js
var serial   = require('@cjssdk/async/serial'),
    taskList = [
        function () {
            return 32;
        },
        function ( callback ) {
            setTimeout(function () {
                callback(null, true);
            }, 10);
        },
        function ( callback ) {
            setTimeout(function () {
                callback(null, 256);
            }, 20);
        },
        function ( callback ) {
            setTimeout(function () {
                callback(null, '512');
            }, 0);
        }
    ];
    
serial(taskList, function ( error, results ) {
    if ( !error ) {
        // results contains array of the given tasks execution results
        // [32, true, 256, '512']
        console.log(results);
    }
});
```


## Contribution ##

If you have any problems or suggestions please open an [issue](https://github.com/cjssdk/async/issues)
according to the contribution [rules](.github/contributing.md).


## License ##

`@cjssdk/async` is released under the [MIT License](license.md).

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