Parallel filter
Parallel asynchronous version of Array#filter, with promised based interface.
Installation
npm install --save parallel-filter
Usage
const got = require('got')
const filter = require('parallel-filter')
filter([1, 2, 3, 4], n => {
return got(`http://is-number-even.com/${n}`, { json: true }).then(res => res.body)
}).then(result => {
console.log(result)
//=> 2, 4
})
API
filter(arr, callback[, thisArg])
Returns a promise of a new array with all elements that pass the asynchronous test implemented by the provided function.
-
arr
Array that will be filtered. -
callback
Function to test each element of the array. Invoked with(element, index, array)
. Return a promise that resolves totrue
to keep the element,false
otherwise. -
thisArg
Optional. Value to use asthis
when executingcallback
.
If any promise provided by the callback
rejects, the promise returned will
immediately reject with that rejection.
See also
- serial-filter - Serial asynchronous version of Array#filter, with promised based interface