The Basic Idea: An Event Loop

This lesson discusses the basic idea behind the event loop.

The basic approach we’ll use, as stated in the last lesson, is called event-based concurrency. The approach is quite simple: you simply wait for something (i.e., an “event”) to occur; when it does, you check what type of event it is and do the small amount of work it requires, which may include issuing I/O requests, or scheduling other events for future handling, etc. That’s it!

Before getting into the details, let’s first examine what a canonical event-based server looks like. Such applications are based around a simple construct known as the event loop. Pseudocode for an event loop looks like this:

Get hands-on with 1200+ tech skills courses.