Test whether some promise passes a testing function
Like Array.some
for promises.
$ npm install --save p-one
const pOne = require('p-one');
const getContinent = require('get-continent'); // not a real module
const places = [
getCapital('Norway').then(info => info.name),
'Bangkok, Thailand',
'Berlin, Germany',
'Tokyo, Japan'
];
const testFunction = async place => {
const continent = await getContinent(place);
return continent === 'europe';
}
(async () => {
const result = await pOne(places, testFunction)
console.log(result);
//=> true
})();
Returns a Promise
that is fulfilled when any promise in input
and ones returned from testFunction
are fulfilled, or rejects if any of the promises reject. The fulfilled value is a boolean
that is true
if any promise passed the test and false
otherwise.
Type: Iterable<Promise|any>
Iterated over concurrently in the testFunction
function.
Type: Function
Expected to return a Promise<boolean>
or boolean
.
Type: Object
Type: number
Default: Infinity
Minimum: 1
Number of concurrently pending promises returned by testFunction
.
- p-every - Test whether all promises passes a testing function
- p-filter - Filter promises concurrently
- p-locate - Get the first fulfilled promise that satisfies the provided testing function
- p-map - Map over promises concurrently
- More…
MIT © Kevin Martensson