2

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 => {
  //
});

4 Answers 4

4

You may choose

const [ productsPromise, variationProductsPromise ] = await Promise.all([Product.findAll(), VariationProduct.findAll()]);

OR

const [ productsPromise, variationProductsPromise ] = await { Product.findAll(), VariationProduct.findAll()}
Sign up to request clarification or add additional context in comments.

Comments

3
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.
}

Comments

2

You can do it like this:

Promise.all([Product.findAll(), VariationProduct.findAll()]).then(data => {
    // data [0] is products
    // data [1] is variationProducts 
}).catch(error => {
    // oops some error
});

Comments

0
const products = Product.findAll();
const variationProducts = VariationProduct.findAll();

const productsPromise = await products;
const variationProductsPromise = await variationProducts;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.