Event Loops and Event Sources
Ase
event loops are a programming facility to execute callback handlers (dispatch event sources) according to expiring Timers, IO events or arbitrary other conditions. A Ase::
while (!loop.finishable()) loop.iterate (true);
Ase::
Traits of the Ase::
- The main loop and its sub loops are handled in round-robin fahsion, priorities below Ase::
EventLoop:: PRIORITY_ASCENT only apply internally to a loop. - Loops are thread safe, so any thready may add or remove sources to a loop at any time, regardless of which thread is currently running the loop.
- Sources added to a loop may be flagged as "primary" (see Ase::
EventSource:: primary()), to keep the loop from exiting. This is used to distinguish background jobs, e.g. updating a window's progress bar, from primary jobs, like processing events on the main window. Sticking with the example, a window's event loop should be exited if the window vanishes, but not when it's progress bar stoped updating.
Loop integration of a Ase::
- First, prepare() is called on a source, returning true here flags the source to be ready for immediate dispatching.
- Second, poll(2) monitors all PollFD file descriptors of the source (see Ase::
EventSource:: add_poll()). - Third, check() is called for the source to check whether dispatching is needed depending on PollFD states.
- Fourth, the source is dispatched if it returened true from either prepare() or check(). If multiple sources are ready to be dispatched, the entire process may be repeated several times (after dispatching other sources), starting with a new call to prepare() before a particular source is finally dispatched.