TermOx
|
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. | |
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.
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().
|
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.
|
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.
auto ox::Event_loop::wait | ( | ) | -> int |
Block until the async event loop returns.
Event_loop::exit(int) must be called to return from wait().