Table of Contents

What is an Event Loop?

About

An Event loop 1) is a thread that waits for and dispatches events or messages that may contains:

An event loop is also known as:

When the event loop in a event-driven system is the entry point, it's referred to:

because it runs on the main thread.

They are responsible for:

Each event shall be processed in a reasonable amount of time to not block the event loop. This means that thread-blocking operations shall not be performed while executed on the event loop, exactly like processing events in a graphical user interface (e.g., freezing a Java / Swing interface by doing a slow network request).

An events can be :

It is almost non-blocking (of kernel threads) allowing it to handle a lot of concurrency (e.g. handle many connections, or messages) using a very small number of kernel threads, which allows it to scale very well.

Features

Event loops are used to implement:

Example

This is how asynchrony is implemented:

Implementation

The event loop got its name from it's minimal implementation:

while (queue.waitForMessage()) {
  queue.processNextMessage()
}

where queue

The event loop works by: