A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/sindresorhus/p-settle below:

sindresorhus/p-settle: Settle promises concurrently and get their fulfillment value or rejection reason with optional limited concurrency

Settle promises concurrently and get their fulfillment value or rejection reason with optional limited concurrency

import fs from 'node:fs/promises';
import pSettle from 'p-settle';

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

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

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:

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.

Type: object

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

The number of concurrently pending promises.

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

This is a type guard for TypeScript users.

This is useful since await pSettle(promiseArray) always returns a PromiseResult[]. This function can be used to determine whether PromiseResult is PromiseFulfilledResult or PromiseRejectedResult.

This is a type guard for TypeScript users.

This is useful since await pSettle(promiseArray) always returns a PromiseResult[]. This function can be used to determine whether PromiseResult is PromiseRejectedResult or PromiseFulfilledResult.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4