Data Processing - Event Loop


Event loop waits for and dispatches events or messages

An event loop is also known as:

  • message dispatcher,
  • message loop,
  • message pump,
  • or run loop

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

  • the main loop
  • or main event loop.

because it runs on the main thread.

They are responsible for:

  • executing the code,
  • collecting and processing events,
  • and executing queued sub-tasks

Event-loops are typical in asynchronous programming models.

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 event loop is one of the methods for implementing inter-process communication.


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

while (queue.waitForMessage()) {

where queue

The event loop works by:

  • making a request to some internal or external event provider (that generally blocks the request until an event has arrived),
  • then calls the relevant event handler (“dispatches the event”).

Documentation / Reference

Powered by ComboStrap