#include <timer.hpp>
Public Types | |
using | OnExpired = std::function< void(Timer &)> |
Signature of the function to be called when the timer expires or is cancelled. More... | |
Public Member Functions | |
Timer ()=delete | |
Timer (Component *parent, std::chrono::milliseconds duration, OnExpired &&on_expired) | |
Constructor. More... | |
Timer (const Timer &)=delete | |
Timer & | operator= (const Timer &)=delete |
Timer (Timer &&)=delete | |
Timer & | operator= (Timer &&)=delete |
~Timer () override=default | |
void | start () |
Start the timer and wait for it to complete asynchronously. More... | |
void | stop () |
Stop the timer if it was running/being waited for. More... | |
void | set_duration (std::chrono::milliseconds duration) |
Set the duration of the timer in future waiting operations. More... | |
Public Member Functions inherited from kouta::base::Component | |
Component ()=delete | |
Component (Component *parent) | |
Constructor. More... | |
Component (const Component &)=delete | |
Component & | operator= (const Component &)=delete |
Component (Component &&)=delete | |
Component & | operator= (Component &&)=delete |
virtual | ~Component () |
Component destructor. More... | |
virtual boost::asio::io_context & | context () |
Obtain a reference to the underlying I/O context. More... | |
void | add_child (Component *component) |
Add a child component to the list. More... | |
void | remove_child (Component *component) |
Remove a child component from the list. More... | |
template<class TClass , class... TMethodArgs, class... TArgs> | |
void | post (void(TClass::*method)(TMethodArgs...), TArgs... args) |
Post a method call to the event loop for deferred execution. More... | |
template<class... TFuncArgs, class... TArgs> | |
void | post (const std::function< void(TFuncArgs...)> &functor, TArgs... args) |
Post a function call to the event loop for deferred execution. More... | |
template<class TFunctor > | |
void | post (TFunctor &&functor) |
Post a functor call to the event loop for deferred execution. More... | |
Private Member Functions | |
void | handle_expiration (const boost::system::error_code &ec) |
Handle the expiration of the internal timer. More... | |
Private Attributes | |
boost::asio::steady_timer | m_timer |
std::chrono::milliseconds | m_duration |
OnExpired | m_on_expired |
using kouta::io::Timer::OnExpired = std::function<void(Timer&)> |
Signature of the function to be called when the timer expires or is cancelled.
|
delete |
|
inline |
Constructor.
[in] | parent | Parent component granting access to the event loop. |
[in] | duration | Duration of the timer. |
[in] | on_expired | Function to call when the timer expires. |
|
delete |
|
delete |
|
overridedefault |
|
inlineprivate |
Handle the expiration of the internal timer.
If the timer expired normally, the internal callback will be executed to notify the external world. Note that said callback will be executed within the context of the event loop as a direct invocation.
[in] | ec | Error code of the asynchronous wait operation. |
|
inline |
Set the duration of the timer in future waiting operations.
The purpose of this method is to allow setting the timer duration without actually starting it, as opposed to start(). However, this method will not affect any running timer awaits, meaning that stop() must be called explicitly if such abehaviour is required.
[in] | duration | New duration for the timer. |
|
inline |
Start the timer and wait for it to complete asynchronously.
The timer will be automatically stopped if it was already running (which could be seen as restarting the timer). The duration used for awaiting the timer is the one already set inside this object.
|
inline |
Stop the timer if it was running/being waited for.
|
private |
|
private |
|
private |