5.1.1 • Published 2 years ago

p-settle v5.1.1

Weekly downloads
78,892
License
MIT
Repository
github
Last release
2 years ago

p-settle

Settle promises concurrently and get their fulfillment value or rejection reason

Install

npm install p-settle

Usage

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,
	}
]
*/

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:

  • status ('fulfilled' or 'rejected', depending on how the promise resolved)
  • value or reason (Depending on whether the promise fulfilled or rejected)
  • isFulfilled
  • isRejected

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

The number of concurrently pending promises.

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

isFulfilled(object)

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.

isRejected(object)

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.

Related

  • p-reflect - Make a promise always fulfill with its actual fulfillment value or rejection reason
  • p-map - Map over promises concurrently
  • More…
brs@open-containers-manager/clicogoportutils@everything-registry/sub-chunk-2396@itoa/adapter-knex@itoa/adapter-mongoose@itoa/fields@itoa/fields-remote-relationshipstarring@compendia/libp2p-commonjs@cybozu/duckipfs-gateway-raceionic-5-versionkahnknightxv-libp2psqs-to-lambda-asynctinkerhub@adpt/core@bee-icons/qwik@bifot/adapter-knex@davidsemakula/keystone-adapter-mongoose@davidsemakula/keystone-fieldswebpack-isomorphic-compiler@ianwalter/dist@infinitebrahmanuniverse/nolb-p-@liyibass/keystonefields@lesliewong007/react-native-version@nois/react-native-version@mdip/libp2p@keystonejs/fields@joakimbeng/react-native-version@koikorn/adapter-knex@koikorn/adapter-mongoose@koikorn/fields@keystone-alpha/fields@keystone-alpha/adapter-knex@keystone-alpha/adapter-mongoose@keystone-next/fields-legacy@keystonejs/adapter-knex@keystonejs/adapter-mongoose@kalamazoo/ci-scripts@keystone-next/adapter-knex-legacy@keystone-next/adapter-mongoose-legacy@pnpm/link-bins@ocopjs/adapter-mongoose@ocopjs/fields@ocopjs/fields-relationship@spencejs/spence-pg-repos@spencejs/spence-tables@rokucommunity/brsmtcrawleep-funp-promise-utilsp-thunkp-suitesequelize-cockroachdbpromise-funprint-servicesee-image-diffnftstorage.linknickhsine-k5-fieldsremote-funcsindresorhus.jsreact-sass-inlinesvgreact-native-versionreact-native-version-autoreact-native-version-extgtfs-to-leveldbmama-exporter@tithon/keystonefields@types/p-settle@uci/base@voussoir/adapter-knex@voussoir/adapter-mongoose@voussoir/fields@teppeis/duckaccess-promisecancel-stuck-transactionscorridoredb-watchdbcpbrighterscriptbrs-engine@shotclock/core
5.1.1

2 years ago

5.1.0

3 years ago

5.0.0

4 years ago

4.1.1

5 years ago

4.1.0

5 years ago

4.0.1

5 years ago

4.0.0

5 years ago

3.1.0

6 years ago

3.0.0

6 years ago

2.1.0

7 years ago

2.0.0

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago