# async-train

> Run N number of async tasks in parallel. As soon as one task is completed it will automatically schedule the next async task. Hence, it always runs N number of async tasks in parallel.

Latest version **1.0.5** (published 2016-10-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install async-train
pnpm add async-train
yarn add async-train
bun add async-train
```

## 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.5 |
| Published | 2016-10-25 |
| First published | 2016-10-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Kundan Kumar |
| Maintainers | kundan1301 |
| Keywords | async, parallel, queue, concurrent, task |

## Links

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

## 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.0.5 (latest) — 2016-10-25
- 1.0.4 — 2016-10-20
- 1.0.3 — 2016-10-20
- 1.0.2 — 2016-10-19
- 1.0.1 — 2016-10-19
- 1.0.0 — 2016-10-19

## README

## Run N number of async tasks in parallel. As soon as one task is completed it will automatically schedule the next async task. Hence, it always runs N number of async tasks in parallel.

#####Optimum CPU utilisation.

# Installation:

```javascript
$ npm install async-train
```

# How to use:

```javascript
var train = require('async-train');
function publish(message,cb){
	// note that this function must be async
	console.log(message);
	process.nextTick(cb);
}
```
### use of mapConcurrentLimit:
mapConcurrentLimit takes array or objects as its first argument, second argument is limit and the third is async function on which all the objects are applied and the last one is callback  which returns all the results after completing all tasks. 


mapConcurrentLimit executes N tasks in parallel where N is the limit as shown in example.

```javascript
function main(){
    var arr = [];
    var limit = 1000;
    for(var i=0;i<10000;i++){
        arr.push(i);
    }
    train.mapConcurrentLimit(arr,limit,publish,function(err,result){
       	if(err) console.log(err);
       	else console.log(result);
    });
}
```


### use of mapConcurrent:

```javascript
function main(){
    var arr = [];
    for(var i=0;i<10000;i++){
        arr.push(i);
    }
    train.mapConcurrent(arr,publish,function(err,result){
       	if(err ) console.log(err);
       	else console.log(result);
    });
}
```

### use of concurrentCallLimit:
concurrentCallLimit takes array of functions or tasks as its argument, second is limit , third is callback which returns all the results after completing all tasks. 


concurrentCallLimit executes N tasks in parallel where N is the limit as shown in example.

```javascript
function main(){
    var arr = [];
    var limit = 1000;
    for(var i=0;i<10000;i++){
        arr.push(function(cb){
        	// this function must be async
        	console.log('Hello');
        	process.nextTick(cb);
        });
    }
    train.concurrentCallLimit(arr,limit,function(err,result){
       	if(err ) console.log(err);
       	else console.log(result);
    });
}
```


### use of concurrentCall:
concurrentCallLimit takes array of functions or tasks as its first argument, second argument is callback which returns all the results after completing all tasks. 


concurrentCallLimit runs all tasks in parallel.

```javascript
function main(){
    var arr = [];
    for(var i=0;i<10000;i++){
        arr.push(function(cb){
        	// this function must be async
        	console.log('Hello');
        	process.nextTick(cb);
        });
    }
    train.concurrentCall(arr,function(err,result){
       	if(err ) console.log(err);
       	else console.log(result);
    });
}
```

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