A question about asynchronous code

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.

If you do NOT use —> Async-Await —> Parallel running code
If you do use ----------> Async-Await —> Sequential running code (wait for part-1 then do part-2)

Async-Await slows down the code and the code-actions.
Why? —> Because now code-part-2 has to wait, till code-part1 is ready!

You can use —> Async-Await or you can use —> .then() - method.

When do i need Async-Await or .then()-method?
Everytime when you need first to get information out of a promise, then you’ll need to work with one of these methods.

Also take a look on Yisraels explanations related to this topic…
https://www.wix.com/velo/forum/tips-tutorials-examples/promises-promises

Brilliant! It looks like I shouldn’t need to change anything after all :slight_smile: