parallel-array
v1.1.1
Published
ParallelArray implements the async functions of forEach、map、every etc
Downloads
21
Readme
ParallelArray
ParallelArray is the subclass of Array, implements some async function, for example: asyncForEach、asyncMap、asyncFilter etc. The funciton of Array which return an instance of Array will return an instance of ParallelArray in ParallelArray.
Install
npm install parallel-array
Quick Example
Init
const arr = new ParallelArray(1, 2, 3, 4, 5)
const arr = ParallelArray.from([1, 2, 3, 4, 5])
const arr = await ParallelArray.asyncFrom([1, 2, 3, 4], async (value) => {
...
})
const arr = ParallelArray.of(1, 2, 3, 4, 5)
Use
import ParallelArray from 'parallel-array'
const arr = new ParallelArray(1, 2, 3, 4, 5)
await arr.asyncForEach(async(value, index, arr) => {
...
}, 3)
await arr.asyncMap(async(value, index, arr) => {
...
}, 2)
await arr.asyncFilter(async(value, index, arr) => {
...
}, 3)
await arr.asyncSome(async(value, index, arr) => {
...
}, 5)
await arr.asyncEvery(async(value, index, arr) => {
...
}, 1)
await arr.asyncSort(async(a, b) => {
...
})
await arr.asyncReduce(async(p, c) => {
...
})
await arr.asyncReduceRight(async(p, c) => {
...
})
await arr.asyncFind(async(value, index, arr) => {
...
})
await arr.asyncFindIndex(async(value, index, arr) => {
...
})
The elements in the array will be gouped by group number, which the default value is the length of array. And the asynchronous function will run in parallel.