TermOx
Public Member Functions | List of all members
ox::Event_loop Class Reference

Calls on loop_function(), and then processes the Event_queue. More...

#include <event_loop.hpp>

Public Member Functions

template<typename F >
auto run (F loop_function) -> int
 Start the event loop, calling loop_function on each iteration. More...
 
template<typename F >
void run_async (F &&loop_function)
 Start the event loop in a separate thread. More...
 
void exit (int return_code)
 Call on the loop to exit at the next exit point. More...
 
auto wait () -> int
 Block until the async event loop returns. More...
 
auto is_running () const -> bool
 Return true if the event loop is currently running.
 
auto exit_flag () const -> bool
 Return true if the exit flag has been set.
 
auto event_queue () -> Event_queue &
 Return a reference to the Event_queue of this loop.
 
auto event_queue () const -> Event_queue const &
 Return a const reference to the Event_queue of this loop.
 

Detailed Description

Calls on loop_function(), and then processes the Event_queue.

Specialized by providing a loop_function to be run at each iteration. The owner of the event loop is responsible for making sure its async thread is shutdown: exit() then wait() before any potentially posted to Widgets are destroyed.

Member Function Documentation

◆ exit()

void ox::Event_loop::exit ( int  return_code)

Call on the loop to exit at the next exit point.

The return code value is used when returning from run() or wait(). This will wait for the calling loop_function to return before exiting. Implement a timeout loop_function() if you need to exit quickly. Not valid to call this method if run() is not currently executing. Only valid to call once per call to run().

◆ run()

template<typename F >
auto ox::Event_loop::run ( loop_function) -> int
inline

Start the event loop, calling loop_function on each iteration.

loop_function should have signature: void(Event_queue&). It should probably append an Event to the provided queue.

◆ run_async()

template<typename F >
void ox::Event_loop::run_async ( F &&  loop_function)
inline

Start the event loop in a separate thread.

loop_function should have signature: void(Event_queue&). It should probably append an Event to the provided queue.

◆ wait()

auto ox::Event_loop::wait ( ) -> int

Block until the async event loop returns.

Event_loop::exit(int) must be called to return from wait().

Returns
the return code passed to the call to exit().

The documentation for this class was generated from the following files: