Hi, I’ve recently finished programming the majority of my website but have never really used ‘async’ or ‘await’ in web development and I’m trying to find out if my code could be optimised. From what I understand, asynchronous code will allow tasks to run in parallel that aren’t reliant on each other as to otherwise waiting on other tasks, which would in turn speed up response times for certain requests, etc? However, I’ve also heard that returning promises is also a form of asynchronous code, with anything inside the .then() running after the completion of the promise, and anything outside running in parallel.
Now here’s the main question:
Almost all of my code contains promise chains and therefore what happens next is dependant on the result of the previous promises in the chain. Eg: getting data from a query, using that data to update another collection, then depending on if the operation is successful or not return a certain message back to the user.
I would assume that this sort of code would not benefit from placing ‘async’ and ‘await’ in my code, as when looking at the documentation it is still clear I would have to be waiting for results to return, it just seems to be written slightly differently. Is this thinking correct or am I completely misunderstanding its purpose here?
Thanks.