JSPM

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

Wait for a specified number of promises to be fulfilled

Package Exports

  • p-some

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-some) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

p-some Build Status

Wait for a specified number of promises to be fulfilled

Useful when you need the fastest of multiple promises.

Install

$ npm install --save p-some

Usage

Checks 4 websites and logs the 2 fastest.

const got = require('got');
const pSome = require('p-some');

pSome([
    got.head('github.com').then(() => 'github'),
    got.head('google.com').then(() => 'google'),
    got.head('twitter.com').then(() => 'twitter'),
    got.head('medium.com').then(() => 'medium')
], 2).then(([first, second]) => {
    console.log(first, second);
    //=> 'google twitter'
});

API

pSome(input, options)

Returns a Promise that is fulfilled when count promises from input are fulfilled. The fulfilled value is an Array of the values from the input promises in the order they were fulfilled. If it becomes impossible to satisfy count, for example, too many promises rejected, it will reject with an AggregateError error.

input

Type: Iterable<Promise|any>

options

Type: Object

count

Required
Type: number (minimum 1)

filter

Type: Function

Receives the value resolved by the promise. Used to filter out values that doesn't satisfy a condition.

pSome.AggregateError

Exposed for instance checking.

License

MIT © Sindre Sorhus