p-settle
Settle promises concurrently and get their fulfillment value or rejection reason
Install
$ npm install p-settle
Usage
const pSettle = require('p-settle');
const promisify = require('pify');
const fs = promisify(require('fs'));
const files = [
'a.txt',
'b.txt' // Doesn't exist
].map(x => fs.readFile(x, 'utf8'));
pSettle(files).then(result => {
console.log(result);
/*
[{
isFulfilled: true,
isRejected: false,
value: '🦄'
},
{
isFulfilled: false,
isRejected: true,
reason: [Error: ENOENT: no such file or directory, open 'b.txt']
}]
*/
});
API
pSettle(input, [options])
Returns a Promise
that is fulfilled when all promises in input
are settled.
The fulfilled value is an array of objects with the following properties:
isFulfilled
isRejected
value
orreason
(Depending on whether the promise fulfilled or rejected)
input
Type: Iterable<Promise|any>
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