Imagine setting a timer for a pizza instead of repeatedly opening the oven. An event-based approach waits for something to happen, then responds with a handler or callback. An event may signal data ready to read, a socket ready to write, or a timer completing. This avoids busy-waiting and lets the application use its time for other work. section 11.1 section 11.0
The approach organizes an application around events or messages rather than one thread or process per task. A typical implementation uses a single-threaded event loop that waits for nonblocking events, identifies each event, performs a small amount of work, and dispatches it to the appropriate callback. This makes it especially useful for high-load, I/O-bound applications with many simultaneous connections. section 11.13 section 11.0
The approach is valuable when:
- Many sockets or messages spend most of their time waiting for I/O; the event loop can respond only when work is ready instead of polling every socket. section 11.1 section 11.13
- An application must remain responsive while communication is in progress; asynchronous tasks let the caller continue without waiting for completion. section 11.13
- The work can be kept brief and nonblocking. A CPU-bound or blocking system call can stop the event loop and therefore block the whole application. section 12.1
From pizza timers to web servers
Instead of checking 10,000 sockets one by one to discover which socket is ready, the application waits for readiness events and processes the reported socket. The same style appears in user interfaces responding to input, web servers handling connections, messaging systems processing messages, and gaming platforms managing activity. section 11.1 section 11.0
