javascript-today

Async I - overview

While always has been good to know how to deal with asynchronous code it is becoming more and more important as programs become more complex. Without asynchronous code our program would only be able to do one thing at a time and would have to wait for the previous instruction to finish before moving on. This works surprisingly well in a lot of instances but whenever we have something that will take awhile to run or return to us is when we should certainly look into using asynchronously.

Very basically what async code allows is for us as programmers to allow the code to continue to run while also waiting for something to return and then do something only after the result or results have returned.

In frontend code this is most often the case when we are calling for a return from a server or database. All requests of this nature should always be handled with async code, even though they are fast (normally less then 500ms) that is still slow and if we didn’t handle the requests with async code the program would look stalled to the user.

In backend code I find that almost everything is best handled with async code and functions just because of the nature of what I am doing on the backend; either calling a database or running a cpu intensive task.

  1. callbacks were the first type of asynchronous code available to us as JavaScript developers.
  2. promises then greatly improved readability and use of asynchronously.
  3. now we have await/async that increases readability again although promises are still more flexible in what they can offer.

Other sites about Async

Next Article: async cont. Callbacks