Event Loop
A single-threaded runtime's mechanism for pulling the next callback off a queue once the call stack is empty.
Event Loop is the mechanism a single-threaded runtime uses to handle asynchronous work: a queue of pending callbacks, and a loop that pulls the next one off and runs it to completion whenever the call stack is empty. Node.js and every browser's JavaScript engine run this way — setTimeout(fn, 0) doesn't run fn immediately, it schedules fn onto the queue, and the loop won't get to it until the currently executing code finishes and the stack empties out.
The consequence that trips people up is that "asynchronous" in this model does not mean "concurrent" in the sense of running at the same time — JavaScript's event loop is single-threaded, so exactly one callback runs at any instant, and a long-running synchronous callback blocks the entire loop, freezing timers, network callbacks, and UI rendering until it returns. This is why a genuinely CPU-heavy task (image processing, a large sort) has to be moved off the main thread entirely — a Web Worker, a worker_threads instance — rather than just wrapped in a Promise, since a promise only reschedules when work runs, not where.
Node's event loop has distinct phases (timers, pending callbacks, poll, check, close) that determine ordering precisely: a setImmediate and a setTimeout(fn, 0) can fire in either order depending on which phase the loop is in when they're scheduled, which is the kind of ordering subtlety that only matters once, in a debugging session, and is otherwise safely ignorable.
The event loop is one specific answer to the concurrency-without-threads problem; the Actor Model is another, structuring concurrency around isolated units of state exchanging messages rather than a shared queue and a single thread of control. Both avoid the shared-mutable-state hazards of true multithreading, from different directions.
See also9
Concurrency and Parallelism
Concurrency is structuring independent tasks together; parallelism is actually running them at the same instant.
Computation & Algorithms8 connections
Process
A running program with its own memory, environment, and identity.
Systems & Tooling33 connections
Race Condition
A defect whose occurrence depends on the relative timing of concurrent operations.
Testing & Verification36 connections
Promise
JavaScript's object for a value that will arrive later, how it replaced nested callbacks, and the microtask queue that decides when its handlers run.
Web Platform10 connections
JavaScript
The programming language of the web browser, written in ten days in 1995, standardized as ECMAScript, and now run everywhere from servers to build tools despite quirks it can never remove.
Web Platform10 connections
requestAnimationFrame
The browser callback that runs once per display frame just before paint, which is the right clock for visual work and stops entirely when nothing is being displayed.
Web Platform12 connections
Background Tab Throttling
Browsers deliberately slow, freeze, or discard pages that are not visible, so code that assumes it keeps running in the background will be wrong.
Web Platform13 connections
Thread Pool
A fixed set of threads kept alive to run many short tasks from a queue, avoiding the cost of creating a thread per task and capping concurrency, with sizing rules and failure modes that shape how servers and runtimes behave under load.
Systems & Tooling10 connections
Web Server
The program that listens for HTTP requests and answers them with files or generated pages, from the first one at CERN in 1990 through Apache's long dominance to event-driven servers built to hold many thousands of connections at once.
Web Platform10 connections
Linked from17
- Actor ModelComputation & Algorithms
A concurrency model where isolated actors communicate only by asynchronous message, never by shared memory.
- Background Tab ThrottlingWeb Platform
Browsers deliberately slow, freeze, or discard pages that are not visible, so code that assumes it keeps running in the background will be wrong.
- Call StackComputation & Algorithms
The region of memory where each function call keeps its local variables and the address to return to, and the source of stack traces, stack overflows, and a classic class of security holes.
- Concurrency and ParallelismComputation & Algorithms
Concurrency is structuring independent tasks together; parallelism is actually running them at the same instant.
- CPU SchedulerSystems & Tooling
The part of the kernel that decides which runnable thread gets each CPU core next, and for how long, trading throughput against latency.
- Fake ClockTesting & Verification
Replacing the real clock in tests with one the test controls, so time-dependent code can be checked at midnight, across DST, or after an hour of retries without waiting.
- InterpreterComputation & Algorithms
A program that executes source code directly, statement by statement, without a separate translation step first.
- JavaScriptWeb Platform
The programming language of the web browser, written in ten days in 1995, standardized as ECMAScript, and now run everywhere from servers to build tools despite quirks it can never remove.
- Long PollingNetworks & Distribution
The ways a client learns that something changed on a server, from asking repeatedly, to holding a request open until there's news, to the push channels that replaced both.
- Long TaskWeb Platform
Any stretch of main-thread work over 50 milliseconds, during which the page can't respond to input, and the techniques for breaking such work up.
- Network SocketNetworks & Distribution
The programming interface through which a program talks to the network, identified by an address and a port, and treated by the operating system as one more file descriptor.
- PromiseWeb Platform
JavaScript's object for a value that will arrive later, how it replaced nested callbacks, and the microtask queue that decides when its handlers run.
- requestAnimationFrameWeb Platform
The browser callback that runs once per display frame just before paint, which is the right clock for visual work and stops entirely when nothing is being displayed.
- System CallSystems & Tooling
The doorway through which a program asks the operating system kernel to do anything privileged, from reading a file to starting a process.
- Thread PoolSystems & Tooling
A fixed set of threads kept alive to run many short tasks from a queue, avoiding the cost of creating a thread per task and capping concurrency, with sizing rules and failure modes that shape how servers and runtimes behave under load.
- Web ServerWeb Platform
The program that listens for HTTP requests and answers them with files or generated pages, from the first one at CERN in 1990 through Apache's long dominance to event-driven servers built to hold many thousands of connections at once.
- Web WorkerWeb Platform
A background thread for running JavaScript off the main thread, with no access to the DOM.