p-every
Test whether all promises passes a testing function
Last updated 7 years ago by kevva .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install p-every 
SYNC missed versions from official npm registry.

p-every Build Status

Test whether all promises passes a testing function

Like Array.every for promises.

Install

$ npm install --save p-every

Usage

const pEvery = require('p-every');
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 pEvery(places, testFunction);
	console.log(result);
	//=> false
})();

API

pEvery(input, testFunction, [options])

Returns a Promise that is fulfilled when all promises 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 all Promises passed the test and false otherwise.

input

Type: Iterable<Promise|any>

Iterated over concurrently in the testFunction function.

testFunction(element, index)

Type: Function

Predicate function, expected to return a Promise<boolean> or boolean.

options

Type: Object

concurrency

Type: number
Default: Infinity
Minimum: 1

Number of concurrently pending promises returned by testFunction.

Related

  • 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…

License

MIT © Kevin Martensson

Current Tags

  • 2.0.0                                ...           latest (7 years ago)

4 Versions

  • 2.0.0                                ...           7 years ago
  • 1.0.2                                ...           9 years ago
  • 1.0.1                                ...           9 years ago
  • 1.0.0                                ...           9 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (3)

Copyright 2013 - present © cnpmjs.org | Home |