Week 10 - Session 1 - Asynchronous JavaScript

blog image source
Synchronous programming means that, barring conditionals and function calls, a code is executed sequentially from top-to-bottom, blocking on long-running tasks such as network requests and disk I/O.

Asynchronous programming means that the engine runs in an event loop. When a blocking operation is needed, the request is started, and the code keeps running without blocking for the result. When the response is ready, an interrupt is fired, which causes an event handler to be run, where the control flow continues. In this way, a single program thread can handle many concurrent operations.


User interfaces are asynchronous by nature and spend most of their time waiting for user input to interrupt the event loop and trigger event handlers. Node is asynchronous by default, meaning that the server works in much the same way, waiting in a loop for a network request, and accepting more incoming requests while the first one is being handled. This is important in JavaScript, because it is a very natural fit for user interface code, and very beneficial to performance on the server.


Synchronous and Asynchronous - http://www.phpmind.com/blog/2017/05/synchronous-and-asynchronous/
JavaScript - from callbacks to async/await - https://medium.freecodecamp.org/javascript-from-callbacks-to-async-await-1cc090ddad99
async.auto - http://ketangupta.in/blog/development/2018/01/19/async-auto/

Popular posts from this blog

Week 9 to 12 - Learning with MCR Codes

Week 8 - Session 1 - JavaScript in the Browser

Week 9 - Session 1 - The Internet, the Web, HTTP