Sitemap

Task Management in JavaScript

1 min readAug 3, 2025

--

In JavaScript, there are operations that are fast (synchronous) and those that are slow (asynchronous), like API calls or timers. The event loop ensures the main thread isn’t blocked by these slow tasks. It places them in either the macrotask queue (e.g., setTimeout, I/O) or microtask queue (e.g., Promises, async/await). While synchronous code runs in the call stack, async tasks are handled later when the stack is clear.

Get Tanmaymone’s stories in your inbox

Join Medium for free to get updates from this writer.

If you want part of your code to wait for a Promise-based (microtask) operation to complete without blocking the whole program, you use async/await. It pauses the async function until the Promise resolves.

While async/await works only with microtasks, macrotasks like setTimeout can be wrapped in Promises to make them awaitable — but their execution still follows macrotask scheduling.

JavaScript runs on a single thread, but handles async operations (like I/O, network requests) using the event loop and callback queue (queue of the things that are done). Call stack is the stack of things being executed at present. If Call stack is engaged in some CPU Intensive task, then whatever is happening in Web APIs section (IO tasks or clock tasks or HTTP request or tasks which are dependent on other resources) and Call back queue has to wait.

--

--