You are working on a web scraping tool. You have multiple URLs to fetch data from, but you want to proceed with the next steps only when data from all URLs are fetched successfully. How would you achieve this using Promises?

  • Use Promise.all()
  • Use Promise.race()
  • Use async/await without Promise.all()
  • Use multiple then() blocks
To proceed with the next steps only when data from all URLs is fetched successfully, you should use Promise.all(). This method takes an array of Promises and resolves only when all of them resolve successfully. Promise.race() resolves on the first success, which is not suitable for this scenario. Using async/await without Promise.all() may not ensure that all URLs are successfully fetched before proceeding.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *