Socket
Socket
Sign inDemoInstall

p-all

Package Overview
Dependencies
1
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    p-all

Run promise-returning & async functions concurrently with optional limited concurrency


Version published
Weekly downloads
1.6M
decreased by-20.36%
Maintainers
1
Install size
21.0 kB
Created
Weekly downloads
 

Package description

What is p-all?

The p-all package is a utility module for running multiple promise-returning & async functions with limited concurrency, aggregating the results. It is useful for controlling the execution of a large number of asynchronous operations to ensure that system resources are managed properly.

What are p-all's main functionalities?

Running multiple promises with limited concurrency

This feature allows you to run multiple promises with a specified concurrency limit. In the code sample, three tasks are executed with a concurrency limit of 2, meaning only two promises will be running at the same time.

const pAll = require('p-all');

const tasks = [
  () => Promise.resolve('Task 1'),
  () => Promise.resolve('Task 2'),
  () => Promise.resolve('Task 3')
];

pAll(tasks, { concurrency: 2 }).then(results => {
  console.log(results); // ['Task 1', 'Task 2', 'Task 3']
});

Other packages similar to p-all

Readme

Source

p-all

Run promise-returning & async functions concurrently with optional limited concurrency

Similar to Promise.all(), but accepts functions instead of promises directly so you can limit the concurrency.

If you're doing the same work in each function, use p-map instead.

See p-series for a serial counterpart.

Install

npm install p-all

Usage

import pAll from 'p-all';
import got from 'got';

const actions = [
	() => got('https://sindresorhus.com'),
	() => got('https://avajs.dev'),
	() => checkSomething(),
	() => doSomethingElse()
];

console.log(await pAll(actions, {concurrency: 2}));

API

pAll(tasks, options?)

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

tasks

Type: Iterable<Function>

Iterable with promise-returning/async functions.

options

Type: object

concurrency

Type: number
Default: Infinity
Minimum: 1

Number of concurrent pending promises.

stopOnError

Type: boolean
Default: true

When set to false, instead of stopping when a promise rejects, it will wait for all the promises to settle and then reject with an AggregateError containing all the errors from the rejected promises.

  • p-map - Map over promises concurrently
  • p-series - Run promise-returning & async functions in series
  • p-props - Like Promise.all() but for Map and Object
  • p-queue - Promise queue with concurrency control
  • p-limit - Run multiple promise-returning & async functions with limited concurrency
  • More…

Keywords

FAQs

Last updated on 22 Apr 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc