AsyncFw 1.2
Async Framework is c++ runtime with timers, poll notifiers, sockets, coroutines, etc.
 
Loading...
Searching...
No Matches
Timer/main.cpp

Timer example

/*
Copyright (c) 2026 Alexandr Kuzmuk
This file is part of the AsyncFw project. Licensed under the MIT License.
See {Link: LICENSE file https://mit-license.org} in the project root for full license information.
*/
#include <iostream>
#include <chrono>
#include <AsyncFw/MainThread>
#include <AsyncFw/Timer>
int main(int argc, char *argv[]) {
int cnt = 0;
timer1.start(10);
timer2.start(20);
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;
}
The Timer class.
Definition Timer.h:15
void start(int, bool=false)
Starts or restarts a timer with the specified timeout. If the timer is already running,...
Definition Timer.cpp:29
FunctionConnectorProtected< Timer >::Connector<> timeout
The Timer::timeout connector.
Definition Timer.h:31