Class EventTimerHandle

Class Documentation

class EventTimerHandle

The EventTimerHandle class represents a timer in the event loop.

An EventTimerHandle is created by calling create_timer. It offers an interface to start and stop the timer. When the handle is destroyed, the timer is removed from the event loop.

The frequency of the timer is passed to the start function. It will be periodically called with the given frequency. The first call happens after the duration has elapsed once.

Public Functions

explicit EventTimerHandle(int fd, const std::shared_ptr<BaseEventLoop> &evloop)

Construct a new EventTimerHandle object.

Not supposed to be called directly. Use create_timer instead.

Parameters:
  • fd – The file descriptor of the timer

  • evloop – The event loop to register the timer with

~EventTimerHandle()

Destroy the EventTimerHandle object.

If this is the last reference to the timer, the timer is removed from the event loop.

EventTimerHandle(const EventTimerHandle&) = default
EventTimerHandle(EventTimerHandle&&) = default
EventTimerHandle &operator=(const EventTimerHandle&) = default
EventTimerHandle &operator=(EventTimerHandle&&) = default
inline void start(const ChronoDuration auto &duration)

Starts the timer.

The timer is started with the given duration. The first call happens after the duration has elapsed once.

Parameters:

duration – The duration to start the timer with

void stop()

Stops the timer.

inline int get_fd() const

Get the file descriptor of the timer.

Returns:

The file descriptor of the timer

inline bool is_running() const

Check if the timer is running.

Returns:

True if the timer is running, false otherwise