This is not

Like what you see? Install OctoLinker now!

Skip to content
Filter promises concurrently
JavaScript TypeScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig Require Node.js 6 Jun 6, 2018
.gitattributes Require Node.js 6 Jun 6, 2018
index.js Refactor TypeScript definition to CommonJS compatible export (#4) Apr 4, 2019
package.json 2.1.0 Apr 4, 2019 Meta tweaks Mar 13, 2019

p-filter Build Status

Filter promises concurrently

Useful when you need to run promise-returning & async functions multiple times with different inputs concurrently and get a filtered down result.


$ npm install p-filter


const pFilter = require('p-filter');
const getWeather = require('get-weather'); // not a real module

const places = [
	getCapital('Norway').then(info =>,
	'Bangkok, Thailand',
	'Berlin, Germany',
	'Tokyo, Japan'

const filterer = async place => {
	const weather = await getWeather(place);
	return weather.temperature > 30;

(async () => {
	const result = await pFilter(places, filterer);

	//=> ['Bangkok, Thailand']


pFilter(input, filterer, [options])

Returns a Promise that is fulfilled when all promises in input and ones returned from filterer are fulfilled, or rejects if any of the promises reject. The fulfilled value is an Array of the fulfilled values returned from filterer in input order.


Type: Iterable<Promise|any>

Iterated over concurrently in the filterer function.

filterer(element, index)

Type: Function

The filterer function that decides whether an element should be included into result. Expected to return boolean | Promise<boolean>.


Type: Object


Type: number
Default: Infinity
Minimum: 1

Number of concurrently pending promises returned by filterer.


  • p-locate - Get the first fulfilled promise that satisfies the provided testing function
  • p-map - Map over promises concurrently
  • p-times - Run promise-returning & async functions a specific number of times concurrently
  • More…


MIT © Sindre Sorhus

You can’t perform that action at this time.