AsyncFw 1.2
Async Framework is c++ runtime with timers, poll notifiers, sockets, coroutines, etc.
 
Loading...
Searching...
No Matches
AsyncFw::Timer Class Reference

The Timer class. More...

#include <AsyncFw/Timer>

Collaboration diagram for AsyncFw::Timer:
[legend]

Public Member Functions

void start (int, bool=false)
 Starts or restarts a timer with the specified timeout. If the timer is already running, it will be restarted.
 
void stop ()
 Stops the timer.
 

Static Public Member Functions

template<typename T>
static void single (int ms, T function)
 Starts a single shot timer with the specified timeout.
 

Public Attributes

FunctionConnectorProtected< Timer >::Connector<> timeout
 The Timer::timeout connector.
 

Detailed Description

The Timer class.

Example:

#include <iostream>
#include <chrono>
#include <AsyncFw/MainThread>
#include <AsyncFw/Timer>
int main(int argc, char *argv[]) {
int cnt = 0;
timer1.start(100);
timer2.start(200);
timer1.timeout([&cnt]() {
std::cout << std::chrono::system_clock::now() << " timer1 timeout" << std::endl;
if (++cnt == 10) AsyncFw::MainThread::exit(0);
});
timer2.timeout([]() { std::cout << std::chrono::system_clock::now() << " timer2 timeout" << std::endl; });
std::cout << "Start Applicaiton" << std::endl;
int ret = AsyncFw::MainThread::exec();
return ret;
}

Member Function Documentation

◆ single()

template<typename T>
static void AsyncFw::Timer::single ( int ms,
T function )
inlinestatic

Starts a single shot timer with the specified timeout.

Parameters
mstimeout interval in milliseconds
functionruns at timeout
Here is the caller graph for this function:

◆ start()

void Timer::start ( int ms,
bool single = false )

Starts or restarts a timer with the specified timeout. If the timer is already running, it will be restarted.

Parameters
mstimeout interval in milliseconds
singleif true, the timer will be a single shot
Here is the call graph for this function:

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