Can someone suggest to me how i can replicate this code with proper error handling without using await ? I would like to run fnA/B/C asynchronously rather than sequentially with await, i would also like to handle all rejections to be handled in the main catch block.
Thanks
async function() {
try {
let a = await fnA();
let b = await fnB();
let c = await fnC();
return(a+b+c);
}
catch(e) {
e.exitCode === 'fnAError' ? doSomething : null;
e.exitCode === 'fnBError' ? doSomething : null;
}
}
After all the suggestions this is what i ended up with:
const caller = async () => {
try {
let promisePool = [];
let a = await testA();
let b = promisePool.push(testB()) - 1;
let c = promisePool.push(testC()) - 1;
let q = await Promise.all(promisePool);
// Get all the non awaited values
console.log(q[b]);
}
catch(e) {
console.log('caller catch');
console.log('ERROR: ' + e);
}
}
Thanks everyone