Skip to content

Commit 41a4e78

Browse files
committed
update readme
1 parent 47147cc commit 41a4e78

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

README.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
# Async parallel forEach #
22
[![npm](https://img.shields.io/npm/v/async-parallel-foreach.svg)](https://www.npmjs.com/package/async-parallel-foreach)
3-
[![npm](./coverage/badge.svg)](https://www.npmjs.com/package/async-parallel-foreach)
4-
[![npm](https://img.shields.io/npm/l/async-parallel-foreach.svg)](https://www.npmjs.com/package/async-parallel-foreach)
3+
[![npm](./coverage/badge.svg)](https://github.com/Donaldcwl/async-parallel-foreach)
4+
[![npm](https://img.shields.io/npm/l/async-parallel-foreach.svg)](https://github.com/Donaldcwl/async-parallel-foreach)
55

6-
Javascript module to perform ***async flow control*** on collection/iterable/dictionary ***in parallel*** and make ***retry easily*** when error occurred
6+
Javascript module to perform ***async flow control*** on collection/iterable/dictionary ***in controlled parallel*** and make ***retry easily*** when error occurred
7+
8+
## Features ##
9+
- iterate collection (array/object/iterator) and ***run async function on each item*** in a collection
10+
- control the ***concurrency*** of running async function on the items
11+
- ***auto retry*** when error occurred
12+
- ***delayed retry***
713

814
## Install ##
9-
```
10-
npm install async-parallel-foreach --save
15+
```bash
16+
npm install async-parallel-foreach async --save
1117
or
12-
yarn add async-parallel-foreach
18+
yarn add async-parallel-foreach async
1319
```
1420

1521
## How to use this module in your project? ##
1622
Frontend: used in framework like React, Angular, Vue etc
1723
(work with bundler like webpack and rollup)
24+
```javascript
25+
import { asyncParallelForEach, BACK_OFF_RETRY } from 'async-parallel-foreach'
26+
```
1827

1928
Backend: node.js
2029
```javascript
21-
import { asyncParallelForEach, BACK_OFF_RETRY } from 'async-parallel-foreach'
30+
const { asyncParallelForEach, BACK_OFF_RETRY } = require('async-parallel-foreach')
2231
```
2332

2433
## API ##
@@ -27,19 +36,20 @@ import { asyncParallelForEach, BACK_OFF_RETRY } from 'async-parallel-foreach'
2736
- coll - can be Array, Object (dictionary), Iterable
2837
- parallelLimit - number of iteratee functions to be executed in parallel at any time, set `parallelLimit = -1` for unlimited parallelization (all items will start process at once)
2938
- iteratee - the function that you define to process each item in "coll"
39+
- if "coll" is array, it will call with (value, index)
40+
- if "coll" is object, it will call with (value, key)
3041
- eachMaxTry - maximum number of times each item will be processed by "iteratee".
3142
- if `eachMaxTry = 2`, then the item will be retried 1 time when there is error throwed in the iteratee function
3243
- add delay before retry
3344
- set `eachMaxTry = { times: 2, interval: 1000 }` // wait for 1000 ms before retry
3445
- interval can also accept function returning the interval in ms
3546
- e.g. `eachMaxTry = { times: 2, interval: (retryCount) => retryCount * 1000 }` // retryCount start from 2 which means it is the 2nd trial
36-
- eachMaxTry follows the "opts" argument in [https://caolan.github.io/async/docs.html#retry](https://caolan.github.io/async/docs.html#retry) "retry"
3747
### BACK_OFF_RETRY strategies ###
3848
- predefined interval function you may use
3949
#### BACK_OFF_RETRY.randomBetween(minMs: number, maxMs: number) ####
50+
- e.g. `eachMaxTry = { times: 5, interval: BACK_OFF_RETRY.randomBetween(100, 3000) }` // random delay between 100ms and 3000ms
4051
#### BACK_OFF_RETRY.exponential() ####
4152
- start from 100ms, then 200ms, 400ms, 800ms, 1600ms, ...
42-
- e.g. `eachMaxTry = { times: 5, interval: BACK_OFF_RETRY.randomBetween(100, 3000) }` // random delay between 100ms and 3000ms
4353

4454
([details api document in here](http://htmlpreview.github.io/?https://github.com/Donaldcwl/async-parallel-foreach/blob/master/docs/index.html))
4555

@@ -131,3 +141,8 @@ cd async-parallel-foreach/example
131141
yarn install # or npm install
132142
node example.js
133143
```
144+
145+
### TODO FEATURES ###
146+
- get current status in the iteratee function e.g. currentTrial, isFirstTrial, isLastTrial, timeElapsed, failedReasons, incrementMaxTry
147+
- eachTrialTimeout, eachItemTimeout
148+
- run iteratee function in web worker for CPU intensive tasks (use tiny-worker for node.js)

0 commit comments

Comments
 (0)