Classes | Public Types | Public Member Functions | Friends | List of all members
event_loop Class Referencefinal

A threaded event loop that supports sending events and timers. More...

#include <event_loop.hpp>

Public Types

enum  loop_option { threadless }
typedef std::deque< std::pair< event_handler *, event_base * > > Events

Public Member Functions

 event_loop ()
 Spawns a thread and starts the loop.
 event_loop (thread_pool &pool)
 Takes a thread from the pool and starts the loop.
 event_loop (loop_option)
 ~event_loop ()
 Stops the thread.
 event_loop (event_loop const &)=delete
event_loopoperator= (event_loop const &)=delete
void filter_events (std::function< bool(Events::value_type &)> const &filter)
 Allows filtering of queued events. More...
void stop (bool join=false)
 Stops the loop. More...
void run ()
 Starts the loop in the caller's thread.
bool running () const


class event_handler

Detailed Description

A threaded event loop that supports sending events and timers.

Timers have precedence over queued events. Too many or too frequent timers can starve processing queued events.

If the deadlines of multiple timers have expired, they get processed in an unspecified order.

See also
event_handler for a complete usage example.
events.cpp, https.cpp, nonblocking_process.cpp, and timer_fizzbuzz.cpp.

Member Function Documentation

◆ filter_events()

void filter_events ( std::function< bool(Events::value_type &)> const &  filter)

Allows filtering of queued events.

Puts all queued events through the filter function. The filter function can freely change the passed events. If the filter function returns true, the corresponding event gets removed.

The filter function must not call any function of event_loop.

Filtering events is a blocking operation and temporarily pauses the loop.

◆ stop()

void stop ( bool  join = false)

Stops the loop.

Stops the event loop. It is automatically called by the destructor.

Does not wait for the loop if the join argument isn't set.

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