Event-driven programming

Event-driven programming is a programming paradigm in which the logical flow and computation are controlled by events such as user-generated actions.

With event-driven programs, computation is typically only performed in response to some event. That event could be a user clicking a mouse or pressing a key on the keyboard, or it could be a sensor returning a new value. While events are not being processed, the program is idle, probably iterating through a main event loop that continues the operation of the program and regularly checks for new events to process.

The following snippet illustrates what a basic event-driven loop might look like:

var isRunning = true
while (isRunning) {
val newestEvent = events.poll()
proccessEvent(newestEvent)
}

The loop may continually check for events until some event processing indicates that the program should terminate.