@tmurphree/promise-all-settled-polyfill v1.0.1
promise-all-settled-polyfill
Implementation of Promise.allSettled so I can use it before it goes GA.
Yes, this is a redundant repo. See here for one example of another copy. But I wanted to write one as well. I wanted something simple.
The main differnce between my implementation and the proposed native implementation is that my implementation only takes an array, not any iterable. I did this because:
1. I needed it to work in a short time.
2. How hard is it to transform an iterable to an array?
3. This is a polyfill for a feature that's coming soon, so there's no value in making it super flexible.
Installation
npm intsall --save --save-exact @tmurphree/promise-all-settled-polyfill
Usage
Use as you would any other function that returns a promise.
The function name is allSettledPolyfill
.
It returns a Promise that resolves to array of objects and rejects to error on bad input.
Output when it { status: 'fulfilled', value: 'some-value' }, { status: 'rejected', reason: }
const axios = require('axios');
const { allSettledPolyfill } = require('@tmurphree/promise-all-settled-polyfill');
allSettledPolyfill([axios.get('http://foo.com'), axios.get('http://bar.com')])
.then((allResults) => {
console.log(allResults);
// something like
// [{ status: 'fulfilled', value: <the value from the API> }, { status: 'rejected', reason: <the error from the API> }]
}))
.catch(console.error);
4 years ago