Dobby 3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
AICommon::Timer Class Reference
Collaboration diagram for AICommon::Timer:
Collaboration graph
[legend]

Public Member Functions

template<typename F , typename... Args>
 Timer (const std::chrono::milliseconds &timeout, F f, Args &&... args)
 Starts a timer that will expire after timeout and execute action.
 
template<typename F , typename... Args>
 Timer (const std::chrono::milliseconds &timeout, TimerType type, TimerThreadPriority prio, F f, Args &&... args)
 
 Timer (Timer &&other)=delete
 
 Timer (const Timer &)=delete
 
Timeroperator= (Timer &&other)=delete
 
Timeroperator= (const Timer &other)=delete
 
 ~Timer ()
 The destructor cancels the timer if it's still not expired.
 
void cancel ()
 Cancels the timer.
 

Private Member Functions

void start (const std::chrono::milliseconds &timeout, TimerType type, TimerThreadPriority prio, const std::function< void()> &callback)
 
void singleShotTimer (TimerThreadPriority prio, const std::chrono::steady_clock::time_point &deadline)
 
void recurringTimer (TimerThreadPriority prio, const std::chrono::milliseconds &interval)
 

Private Attributes

std::function< void()> mCallback
 
std::thread mTimerThread
 
Mutex mLock
 
ConditionVariable mCond
 
bool mCancel
 

Constructor & Destructor Documentation

◆ Timer()

template<typename F , typename... Args>
AICommon::Timer::Timer ( const std::chrono::milliseconds &  timeout,
f,
Args &&...  args 
)
inline

Starts a timer that will expire after timeout and execute action.

Parameters
Thesecond parameter is a function to be called on expiry, and third an later are (optional) arguments to it. eg.: auto t1 = Timer(minutes(30), orderBeer, 5, "Fursty Ferret"); auto t2 = Timer(hours(3), leavePub);

◆ ~Timer()

Timer::~Timer ( )

The destructor cancels the timer if it's still not expired.

Note
If the action is executing it will block until it finishes.

Member Function Documentation

◆ cancel()

void Timer::cancel ( )

Cancels the timer.

Note
if you call it more than once, subsequent calls will be ignored.

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