Skip to content
Settle promises concurrently and get their fulfillment value or rejection reason
JavaScript TypeScript
Branch: master
Clone or download
Latest commit 2bb2f30 Apr 30, 2019

readme.md

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(promises, [options])

Returns a Promise<Object[]> that is fulfilled when all promises in promises are settled.

The objects in the array have the following properties:

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

promises

Type: Array<Promise<unknown>>

options

Type: Object

concurrency

Type: number
Default: Infinity
Minimum: 1

Number of concurrently pending promises.

Related

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

License

MIT © Sindre Sorhus

You can’t perform that action at this time.