# TimeWheel **Repository Path**: tjopenlab/TimeWheel ## Basic Information - **Project Name**: TimeWheel - **Description**: https://github.com/zhe-ma/TimeWheel C++ implementation of hierarchy time wheel - **Primary Language**: C++ - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-08-09 - **Last Updated**: 2024-08-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## TimeWheel - C++11 implementation of hierarchy time wheel - Customizable time wheel. - Customizable timer frequency(ms). ## Build ```bash $ mkdir build $ cd build $ cmake -DCMAKE_BUILD_TYPE=debug .. $ make -j4 $ ./build/timw-wheel ``` ### Example ```cpp int main() { // Four level time wheels: Hour, Minute, Secon, Millisecond. int timer_step_ms = 50; TimeWheelScheduler tws(timer_step_ms); // Hour time wheel. 24 scales, 1 scale = 60 * 60 * 1000 ms. tws.AppendTimeWheel(24, 60 * 60 * 1000, "HourTimeWheel"); // Minute time wheel. 60 scales, 1 scale = 60 * 1000 ms. tws.AppendTimeWheel(60, 60 * 1000, "MinuteTimeWheel"); // Second time wheel. 60 scales, 1 scale = 1000 ms. tws.AppendTimeWheel(60, 1000, "SecondTimeWheel"); // Millisecond time wheel. 1000/timer_step_ms scales, 1 scale = timer_step ms. tws.AppendTimeWheel(1000 / timer_step_ms, timer_step_ms, "MillisecondTimeWheel"); tws.Start(); tws.CreateTimerAt(GetNowTimestamp() + 10000, []() { std::cout << "At now+10s" << std::endl; }); tws.CreateTimerAfter(500, []() { std::cout << "After 0.5s" << std::endl; }); std::cout << timetoStr() << std::endl; auto timer_id = tws.CreateTimerEvery(5000, []() { std::cout << "Every 5s: " << timetoStr() << std::endl; }); tws.CreateTimerEvery(30 * 1000, []() { std::cout << "Every 30s: " << timetoStr() <