a header-only event-driven library based on c++11.
APACHE-2.0 License
a header-only timer based on c++11.
c++11:)
example/test.cc
#include <iostream>
#include "event_pool/import.h"
int main() {
// EventPool
EventPool::EventPool pool(102400);
// start
pool.Start();
// TimeEventexitfalsetruepoolStop
EventPool::TimeEvent time_event(std::chrono::seconds(2));
time_event.SetCallBack([](bool exit) -> bool {
if (exit == true) {
std::cout << "pool exit" << std::endl;
return false;
}
std::cout << "hello world" << std::endl;
return true;
});
// TimeEventstd::chrono::duration
// true+duration
//
// std::chrono::time_point
// true or false
EventPool::TimeEvent time_event2(EventPool::SecondsAfter(5));
time_event2.SetCallBack([](bool exit) -> bool {
if (exit == true) {
std::cout << "pool exit" << std::endl;
return false;
}
std::cout << "hello world2" << std::endl;
return false;
});
// PushTimeEventpool
pool.PushTimeEvent(std::move(time_event));
auto handler = pool.PushTimeEvent(std::move(time_event2));
// 8s
std::this_thread::sleep_for(std::chrono::seconds(8));
// PushTimeEventhandlerhandlerStop
// Stoptrue
// Stoptrue
// time pointhandler->Stop
bool succ = handler->Stop();
if (succ == true) {
std::cout << "time event stop succ!" << std::endl;
}
std::this_thread::sleep_for(std::chrono::seconds(7));
// Stoptrue
// EventPool
pool.Stop();
return 0;
}