Event loop
An event loop is a runtime mechanism that repeatedly selects and dispatches ready events, tasks, or callbacks for execution.
Python Concurrency with asyncio
An event loop is a control mechanism that repeatedly selects runnable work, executes it, and responds when suspended work becomes ready.
- How it is used
- Coordinates asyncio tasks so I/O-bound operations progress concurrently without stopping a single Python thread.
- How deep it goes
- Explains queues, suspension, socket selectors, timeouts, manual management, and a simplified custom implementation, while deferring production completeness.
- Examples
- Uses web requests, non-blocking socket selectors, asyncio echo servers, Tkinter loops, and a custom socket server.
- What you can do after
- Build and operate asyncio applications, schedule coroutines, manage loops, and diagnose blocking CPU-bound or I/O code.
Read how Python Concurrency with asyncio explains event loop →
JavaScript in Depth
The event loop is the scheduling mechanism that repeatedly selects queued work and dispatches it for execution in a JavaScript runtime.
- How it is used
- Coordinates scheduled JavaScript callbacks and helps explain execution-order surprises and performance delays.
- How deep it goes
- Explains queued events and run-to-completion, then applies queue behavior to starvation and diagnosis without specifying one universal runtime implementation.
- Examples
- Contrasts a callback-output puzzle across runtimes and module formats with cases where low aggregate CPU conceals a saturated loop.
- What you can do after
- Diagnose/debug with it by tracing callback ordering, recognizing microtask starvation, and separating event-loop saturation from process-wide CPU usage.
Secrets of the JavaScript Ninja, Second Edition
A runtime scheduling mechanism that coordinates when queued events and callbacks are handled by an application.
- How it is used
- Coordinates event handlers and other browser work during interactive page execution.
- How deep it goes
- Builds from a single event queue to macrotask and microtask queues, then works through delayed timer execution.
- Examples
- Traces mousemove and click DOM updates and a queued click, timeout, and interval timing scenario.
- What you can do after
- Diagnose/debug why an event or timer handler waits despite its event occurring or its delay expiring.
Read how Secrets of the JavaScript Ninja, Second Edition explains event loop →
Latency
An event loop is a control-flow pattern that waits for events, detects activity from event sources, and dispatches events to handlers.
- How it is used
- Coordinates I/O-bound concurrent work and multiplexes operations across many connections while waiting for events.
- How deep it goes
- Develops the poll-dispatch-task cycle through a Rust loop sketch, OS notification interfaces, and nonblocking handler constraints.
- Examples
- Illustrates asynchronous database queries, socket-readiness events, and a Rust loop with scheduled tasks.
- What you can do after
- Evaluate event-loop designs by distinguishing safe idle polling from blocking handlers and considering future-related overhead.
Grokking Concurrency
An event loop is a control-flow pattern that repeatedly waits for pending events, selects their handlers, and invokes those handlers.
- How it is used
- Coordinates callbacks and cooperative tasks so a server can handle multiple clients concurrently in one thread.
- How deep it goes
- Builds queue-based, socket-readiness, and coroutine-scheduling loops, then extends one with a thread pool; the final demonstration is not production-ready.
- Examples
- Uses knock-knock events, a Fibonacci coroutine, and successive pizza-server implementations to illustrate dispatch and scheduling.
- What you can do after
- Builds an event loop from scratch to dispatch callbacks or schedule cooperative coroutines in a server.
The Joy of JavaScript
An event loop is a runtime scheduling mechanism that repeatedly dequeues and executes pending callbacks or tasks to drive asynchronous execution.
- How it is used
- Places the event loop behind callbacks, promises, and async/await as the scheduling model for asynchronous JavaScript.
- How deep it goes
- Explains the callback queue and interleaved scheduling at a high level, without detailing queue rules or engine internals.
- Examples
- Contrasts synchronous, callback-based, and promise-based Node.js file reads and considers a module using top-level await.
- What you can do after
- Evaluate/understand how asynchronous work can proceed alongside main code and why dependent modules wait at top-level await.
Build a Frontend Web Framework (From Scratch)
The JavaScript runtime mechanism that coordinates execution of synchronous code and queued asynchronous tasks.
- How it is used
- Coordinates asynchronous lifecycle hooks, scheduler jobs, user interactions, timers, and DOM rendering.
- How deep it goes
- Explains the execution stack, two queues, four cycle steps, and microtask priority without pursuing full specification detail.
- Examples
- Uses event listeners, timers, promise callbacks, lifecycle hooks, nextTick(), and scheduler jobs.
- What you can do after
- Evaluate asynchronous ordering and schedule lifecycle or update work using microtasks.
Read how Build a Frontend Web Framework (From Scratch) explains event loop →
Building LLM Applications with DSPy
An event loop schedules and runs asynchronous tasks, switching between them when they complete or suspend.
- How it is used
- Coordinates coroutine tasks, switching between them when a task completes or pauses at an await point.
- How deep it goes
- Explains task switching at await points and that only one task executes at a time.
- Examples
- Demonstrates two sleeping coroutines run with asyncio.gather(), with their results and elapsed time printed.
- What you can do after
- Apply via asyncio.run() to start an event loop and run coroutine tasks.
Read how Building LLM Applications with DSPy explains event loop →
Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi
An event loop is a control structure that repeatedly waits for input or events and dispatches corresponding handlers.
- How it is used
- Runs interactive Pygame controls and live camera applications that repeatedly receive input, process data, display results, and detect exit requests.
- How deep it goes
- Implements initialization, polling, dispatch, frame-rate control, exit handling, camera cleanup, and face processing without exploring lower-level scheduling internals.
- Examples
- Uses a Pygame event printer and a live camera preview that marks detected faces until window, Q, or Esc input ends execution.
- What you can do after
- Apply it via Pygame or cv2 to build responsive input handlers, camera previews, controlled exits, and reusable robot interaction loops.
Read how Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi explains event loop →
Spring in Action, Sixth Edition
An event loop is a concurrency mechanism that repeatedly receives events and dispatches their handlers, typically without dedicating a thread to each request.
- How it is used
- Uses event-driven request handling to improve scalability in reactive web applications and APIs.
- How deep it goes
- Explains request, callback, and completion-event flow, then contrasts event-loop handling with servlet-based multithreading.
- Examples
- Illustrates callbacks for intensive database and network operations and visualizes handling more requests with fewer threads.
- What you can do after
- Apply it via Spring WebFlux when building reactive APIs that use nonblocking asynchronous request handling.
Read how Spring in Action, Sixth Edition explains event loop →
Grokking Simplicity
A runtime mechanism that repeatedly retrieves queued events or callbacks and invokes them when the call stack is available.
- How it is used
- Coordinates browser events and asynchronous callbacks while isolating separate execution timelines.
- How deep it goes
- Defines jobs, callbacks, queue processing, and single-threaded execution, then traces a complete AJAX interaction.
- Examples
- Uses click handling, AJAX cart updates, nested dog-and-cat requests, and a dishwashing callback refactoring exercise.
- What you can do after
- Apply it via JavaScript callbacks to structure asynchronous results instead of relying on immediate return values.
The Well-Grounded Python Developer: How the pros use Python and Flask
An event loop is a control structure that waits for events and repeatedly dispatches them for processing.
- How it is used
- Keeps a Flask web server responsive by waiting for incoming HTTP requests and dispatching them to defined routes.
- How deep it goes
- Defines event waiting and dispatch behavior, but stops short of showing the loop’s internal implementation.
- Examples
- Uses a Flask home route on port 5000 and an undefined /something route that produces a 404 response.
- What you can do after
- Operate a Flask server and understand how it remains active while waiting for requests.
Read how The Well-Grounded Python Developer: How the pros use Python and Flask explains event loop →
Acing the Frontend Interview
The event loop is the JavaScript runtime mechanism that schedules queued callbacks and other tasks for execution when the call stack is available.
- How it is used
- Supports responsive web applications during API requests, animations, and user interactions.
- How deep it goes
- Explains the call stack, task queues, microtasks, and macrotasks, then points toward concurrency architecture.
- Examples
- Uses API requests, animations, user interactions, and asynchronous ordering issues as practical contexts.
- What you can do after
- Evaluate/understand asynchronous execution, debug ordering issues, and explain concurrency trade-offs in interviews.
Secrets of the JavaScript Ninja, Third Edition
An event loop is a mechanism that repeatedly processes queued tasks and callbacks to support asynchronous, event-driven execution.
- How it is used
- Explains how browser-side JavaScript responds to user actions and how queued callbacks run.
- How deep it goes
- Defines single-threaded queue processing and distinguishes prioritized microtasks from task-queue callbacks.
- Examples
- Contrasts end-of-script logging with a promise callback and a setTimeout callback.
- What you can do after
- Evaluate asynchronous callback order by comparing promise microtasks with setTimeout tasks.
Read how Secrets of the JavaScript Ninja, Third Edition explains event loop →
Also covered in
- Enterprise RAGIn early access (MEAP)
- Fast Python: High performance techniques for large datasets
- Go in Practice, Second Edition
- Designing AI SystemsIn early access (MEAP)
- Quarkus in Action
- C++ Concurrency in Action, Second Edition
- MongoDB 8.0 in Action, Third Edition
What to know first
- asynchronous programmingAsynchronous programming structures operations so that the initiating execution can continue or yield control without synchronously waiting for each operation to complete.
- threadA thread is a distinct sequence of execution with its own control flow and state, managed or scheduled by a processor, runtime, or operating system.
- taskA task is a discrete unit of work, activity, or computation to be performed or completed.
- Document Object ModelThe Document Object Model is a platform-independent programming interface that represents a document as a structured tree of nodes and provides ways to access and modify its content and structure.
Related concepts
- microtask queueuses · A microtask queue is an event-loop queue that holds pending microtasks for processing after the current synchronous execution and before subsequent task processing.
- queueuses · A queue is an ordered collection that holds items for retrieval or processing, commonly in first-in, first-out order.
- macrotask queueuses · A macrotask queue is a runtime-managed queue of scheduled tasks awaiting processing by an event loop.
- callbackuses · A callback is a function or other callable supplied or registered with a component for invocation at a specified event, condition, or point in execution.
- eventuses · A software event is an occurrence, state change, or notification that a system can detect, record, communicate, or handle.
- JavaScriptused by · JavaScript is a high-level, dynamically typed programming language standardized as ECMAScript and used for web and general-purpose programming.
Questions about event loop
What is event loop?
An event loop is a runtime mechanism that repeatedly selects and dispatches ready events, tasks, or callbacks for execution.
Which Manning books explain event loop?
Python Concurrency with asyncio, JavaScript in Depth, Secrets of the JavaScript Ninja, Second Edition, Latency, Grokking Concurrency, The Joy of JavaScript, Build a Frontend Web Framework (From Scratch), Building LLM Applications with DSPy and 6 more.
What should I know before learning event loop?
Manning books that teach event loop usually introduce asynchronous programming, thread, task and Document Object Model first.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.













