JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5795872
  • Score
    100M100P100Q199285F
  • License MIT

Filter promises concurrently

Package Exports

  • p-filter
  • p-filter/index

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (p-filter) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.

Install

$ npm install --save p-filter

Usage

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

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

const filterer = el => getWeather(el).then(place => place.temperature > 30);

pFilter(places, filterer).then(result => {
    console.log(result);
    //=> [{name: 'Bangkok, Thailand', temperature: 36}]
});

API

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.

input

Type: Iterable<Promise|any>

Iterated over concurrently in the filterer function.

filterer(element, index)

Type: Function

Expected to return a boolean or a Promise for a boolean.

options

Type: Object

concurrency

Type: number
Default: Infinity

Number of concurrently pending promises returned by filterer. Minimum 1.

License

MIT © Sindre Sorhus