Promise All from Object
- Polyfill Promise on old browsers
- Promise.all({...})
$ npm install --save @antoninlanglade/promise-all-obj
import PromiseAllObj from 'promise-all-obj' // web
// or
const PromiseAllObj = require('promise-all-obj') // node
var testObj = {
promise1: new Promise((res, rej) => {
setTimeout(() => res('p1'), 2000)
}),
promise2: new Promise((res, rej) => res('p2'))
};
PromiseAllObj(testObj)
.then((results) => console.log(results)) // {promise1: 'p1', promise2: 'p2'}
.catch((err) => console.log(err)) // Errors