With node v10.15.1 I try to use Promise.allSettled()
to executes batches of Promise but it throw me an error
TypeError: Promise.allSettled is not a function
Is Promise.all()
returning a promise ?
The Main
function below return an object.
Other functions use some Promises to create its "sub-object".
Why I need "batch of promise" : To create a sub-object, all the required promises must be settled. But not all the sub-objects are needed in the "main object".
const path = require('path');
const os = require('os');
const si = require('systeminformation');
function getFoo() {
// all these promises have to be settled to construct the sub-object
return Promise.all([si.system(), si.chassis()]).then(([system, chassis]) => {
return { /* hidden for brevity : use system and chassis to return a single object */ };
})
.catch(ex => { /* hidden for brevity */ });
}
function getBar() {
// all these promises have to be settled to construct the sub-object
return Promise.all([si.osInfo(), si.uuid()]).then(([osInfo, uuid]) => {
return { /* hidden for brevity : use osInfo and uuid to return a single object */ };
})
.catch(ex => { /* hidden for brevity */ });
}
function getBaz() {
// all these promises have to be settled to construct the sub-object
return Promise.all([os.networkInterfaces(), si.networkInterfaceDefault()]).then(([interfaces, defaultInterface]) => {
return { /* hidden for brevity : use interfaces and defaultInterface to return a single object */ };
})
.catch(ex => { /* hidden for brevity */ });
}
function Main() {
// some of these promises can be rejected
Promise.allSettled([ getFoo(), getBar(), getBaz() ])
.then(([foo, bar, baz]) => {
return { foo, bar, baz }
})
.catch(ex => { /* hidden for brevity */ });
}
Main();
One Example of expected object
{
foo: {
prop: 'example',
someOtherProps: 'We are there!'
},
baz: {
test: 50
}
}