So yeah, I’m working on a project I think I’ve encountered a problem… Is there a much better way to clean this up. Everything works as it is but I think I remember learning about something for this specific situation?
Promise.all. This code says you only want the prices to be rendered if all the prices can be resolved, so you should use that (if that isn’t what you want, then you’re making each request depend on the previous one succeeding).
You could chain your promises here but it looks like there is no reason to because the next promise doesn’t rely on any data from the previous promise.
Right now all the price checks are happening sequentially, chaining the promises will do the same thing but with a cleaner syntax to avoid the callback hell style.
Instead of getting all the values sequentially like you are doing here you do it concurrently, calling each price check at the same time instead of waiting for the previous to finish first.
Yeah, I’m begining to notice that.
I’m not going to lie I’ve been somewhat skimming the whole promise thing because I find it so confusing. I’ll just have to start filling the gaps in my knowledge about promises.