🚀 Big News:Socket Has Acquired Secure Annex.Learn More
Socket
Book a DemoSign in
Socket

p-settle

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

p-settle

Settle promises concurrently and get their fulfillment value or rejection reason

Source
npmnpm
Version
4.0.1
Version published
Weekly downloads
631K
-8.74%
Maintainers
1
Weekly downloads
 
Created
Source

p-settle Build Status

Settle promises concurrently and get their fulfillment value or rejection reason

Install

$ npm install p-settle

Usage

const {promises: fs} = require('fs');
const pSettle = require('p-settle');

(async () => {
	const files = [
		'a.txt',
		'b.txt' // Doesn't exist
	].map(fileName => fs.readFile(fileName, 'utf8'));

	console.log(await pSettle(files));
	/*
	[
		{
			isFulfilled: true,
			isRejected: false,
			value: '🦄'
		},
		{
			isFulfilled: false,
			isRejected: true,
			reason: [Error: ENOENT: no such file or directory, open 'b.txt']
		}
	]
	*/
})();

API

pSettle(array, options?)

Returns a Promise<object[]> that is fulfilled when all promises from the array argument are settled.

The objects in the array have the following properties:

  • isFulfilled
  • isRejected
  • value or reason (Depending on whether the promise fulfilled or rejected)

array

Type: Array<ValueType | PromiseLike<ValueType> | ((...args: any[]) => PromiseLike<ValueType>)>

The array can contain a mix of any value, promise, and async function. Promises are awaited. Async functions are executed and awaited. The concurrency option only works for elements that are async functions.

options

Type: object

concurrency

Type: number (Integer)
Default: Infinity
Minimum: 1

Number of concurrently pending promises.

Note: This only limits concurrency for elements that are async functions, not promises.

  • p-reflect - Make a promise always fulfill with its actual fulfillment value or rejection reason
  • p-map - Map over promises concurrently
  • More…

Keywords

promise

FAQs

Package last updated on 29 Mar 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