Have to run both codes at a single time. Don't want to wait and then fire next query but wait for both query execution complete.
products = await Product.findAll()
.then(data => {
return data;
})
.catch(error => {
//
});
variationProducts = await VariationProduct.findAll()
.then(data => {
return data;
})
.catch(error => {
//
});
You may choose
const [ productsPromise, variationProductsPromise ] = await Promise.all([Product.findAll(), VariationProduct.findAll()]);
OR
const [ productsPromise, variationProductsPromise ] = await { Product.findAll(), VariationProduct.findAll()}
try {
const [products, variationProducts] = await Promise.all([
Product.findAll(),
VariationProduct.findAll()
]);
// Do what you need with the result;
}
catch(e) {
console.error('Problem in getting data', e);
throw e; // Or do what you want.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With