JavaScript

An attempt to understand asynchronous programming

JavaScript is a synchronous, single-threaded, blocking language. It is the JavaScript run-time of Node.js (and browsers) - containing the Event Loop & the Task Queue - that enable asynchronous programming with JavaScript.

Callbacks

Callback functions are not intrinsically asynchronous. The JavaScript run-times add the callback functions to the task queue and the event loop executes them after the current instructions on main thread are processed.

Promises

Promises have their own micro-queue, which has higher precedence over the task-queue.

Async & Await

Async functions are called synchronously - @jaffathecake

Async functions are called synchronously. It is the awaited part of an async function that is run asynchronously. Everything before the await is run asynchronously.

Awaited results are cast to Promises and their values are not available until the next micro-task checkpoint. Micro-tasks are not executed until the script completes.