Codacoda
Back to Academy

concurrency

Event Loop

The event loop is a concurrency model that runs a single-threaded loop continuously checking for and dispatching events or callbacks. Instead of using multiple threads, it achieves concurrency by never blocking: I/O operations are registered with callbacks and the loop processes completed events one at a time. This model powers Node.js, browser JavaScript, and Python's asyncio. It excels at I/O-bound workloads but can be blocked by CPU-intensive tasks on the main thread.

Use Cases

  • Node.js web servers handling thousands of concurrent connections on one thread
  • Browser rendering and user interaction handling via the JavaScript event loop
  • GUI applications processing user events without freezing the interface
  • Asyncio-based Python servers for high-concurrency network applications

Visualization

INITIALCall StackMicrotask QueueMacrotask QueueOutputEvent Loopidle
Speed:1x
The event loop processes: 1) Call Stack, 2) ALL Microtasks, 3) ONE Macrotask, repeat.Step 1 / 7

Implementation

Output

Click "Run Code" to see output...