easy timer
easy timer
使用示例:
easy::Timer timer;
bar b;
std::vector<int> taskids;
auto curr = system_clock::now();
std::cout << "> timer " << ": " << (duration<double>(curr - now)).count() << "s => Start!" << std::endl;
taskids.push_back(timer.add(foo, curr + seconds(2)));
taskids.push_back(timer.add(std::bind(&bar::hello, b), curr + seconds(3), seconds(3), 3));
taskids.push_back(timer.add(
[ = ]() { std::cout << (duration<double>(system_clock::now() - now)).count() << "s => func lambda" << std::endl; },
curr + seconds(4), seconds(2)));
std:
:sleep_for(seconds(10));
for (auto id : taskids)
{
std::cout << "> timer " << ": del " << id << std::endl;
timer.del(id);
}
timer.stop();
curr = system_clock::now();
std::cout << "> timer " << ": " << (duration<double>(curr - now)).count() << "s => Stop!" << std::endl;
timer嵌套 每天一个定时器做当天任务:
easy::Timer g_timer;
g_timer.add([ = ]()
{
easy::Timer timer;
bar b;
std::vector<int> taskids;
auto curr = system_clock::now();
std::cout << "> timer " << ": " << (duration<double>(curr - now)).count() << "s => Start!" << std::endl;
taskids.push_back(timer.add(foo, curr + seconds(2)));
taskids.push_back(timer.add(std::bind(&bar::hello, b), curr + seconds(3), seconds(3), 3));
taskids.push_back(timer.add(
[ = ]() { std::cout << (duration<double>(system_clock::now() - now)).count() << "s => func lambda" << std::endl; },
curr + seconds(4), seconds(2)));
std:
:sleep_for(seconds(10));
for (auto id : taskids)
{
std::cout << "> timer " << ": del " << id << std::endl;
timer.del(id);
}
timer.stop();
curr = system_clock::now();
std::cout << "> timer " << ": " << (duration<double>(curr - now)).count() << "s => Stop!" << std::endl;
},
system_clock::now() + seconds(4), seconds(15));
std:
:sleep_for(seconds(60));