Socket
Socket
Sign inDemoInstall

p-some

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

p-some

Wait for a specified number of promises to be fulfilled


Version published
Maintainers
1
Created

What is p-some?

The p-some npm package allows you to wait for a specified number of promises to be fulfilled. It is useful when you need only a certain number of promises to resolve successfully, and you don't care about the rest.

What are p-some's main functionalities?

Wait for a specified number of promises to fulfill

This feature allows you to wait for a specified number of promises to be fulfilled. In this example, we have an array of promises, and we use p-some to wait for any 2 of them to resolve successfully. The result will be an array of the first 2 resolved values.

const pSome = require('p-some');
const promises = [
  Promise.resolve(1),
  Promise.resolve(2),
  Promise.reject(new Error('error')),
  Promise.resolve(3)
];

pSome(promises, { count: 2 }).then(values => {
  console.log(values); // [1, 2]
});

Handle rejected promises

This feature demonstrates how p-some handles rejected promises. In this example, we have an array of promises with some of them being rejected. p-some will still wait for the specified number of promises to be fulfilled and will return the resolved values. If it cannot fulfill the count due to too many rejections, it will throw an error.

const pSome = require('p-some');
const promises = [
  Promise.resolve(1),
  Promise.reject(new Error('error1')),
  Promise.reject(new Error('error2')),
  Promise.resolve(2)
];

pSome(promises, { count: 2 }).then(values => {
  console.log(values); // [1, 2]
}).catch(error => {
  console.error(error);
});

Other packages similar to p-some

Keywords

FAQs

Package last updated on 19 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc