{"id":20355906,"url":"https://github.com/hedzr/ticker-cxx","last_synced_at":"2025-04-12T02:51:10.969Z","repository":{"id":50330530,"uuid":"518787662","full_name":"hedzr/ticker-cxx","owner":"hedzr","description":"c++17 timing and trigger abilities","archived":false,"fork":false,"pushed_at":"2024-12-11T22:54:48.000Z","size":555,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T22:35:32.580Z","etag":null,"topics":["alarm","alarmmanager","cpp17","scheduled-tasks","scheduler","ticker","timer","timingwheel"],"latest_commit_sha":null,"homepage":"https://hedzr.com/c++/algorithm/ticker-timer-within-cxx17/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hedzr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":"https://paypal.me/hezr/5"}},"created_at":"2022-07-28T09:45:56.000Z","updated_at":"2025-03-04T06:58:19.000Z","dependencies_parsed_at":"2024-12-06T01:21:39.032Z","dependency_job_id":"e2a2a05d-6fab-4fe4-8d7a-fd352bb84097","html_url":"https://github.com/hedzr/ticker-cxx","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hedzr%2Fticker-cxx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hedzr%2Fticker-cxx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hedzr%2Fticker-cxx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hedzr%2Fticker-cxx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hedzr","download_url":"https://codeload.github.com/hedzr/ticker-cxx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248509254,"owners_count":21115970,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alarm","alarmmanager","cpp17","scheduled-tasks","scheduler","ticker","timer","timingwheel"],"created_at":"2024-11-14T23:14:26.234Z","updated_at":"2025-04-12T02:51:10.950Z","avatar_url":"https://github.com/hedzr.png","language":"C++","funding_links":["https://paypal.me/hezr/5"],"categories":[],"sub_categories":[],"readme":"# ticker-cxx\n\n![CMake Build Matrix](https://github.com/hedzr/ticker-cxx/workflows/CMake%20Build%20Matrix/badge.svg) \u003c!-- \n![CMake Build Matrix](https://github.com/hedzr/ticker-cxx/workflows/CMake%20Build%20Matrix/badge.svg?event=release) \n--\u003e [![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/hedzr/ticker-cxx.svg?label=release)](https://github.com/hedzr/ticker-cxx/releases)\n\n`ticker-cxx` is a C++17 library to provide a set of timing ticker functions, it schedules to trigger your customized tasks.\n\n**WIP**.\n\n## Features\n\nThese template classes are provided for scheduling your works mainly:\n\n- timer\n- ticker\n- alarm\n\nThe typical time and period representations, such as `1us`, from `std::literals::chrono_literals`, are valid for the timer setting.\n\nThe recommended shortest gap is `1us`.\n\nTo support `ns`/`nanoseconds` level as interval gap, you should tune and optimize the whole userland codes and this library. Or, use hardware clock device and driver.\n\nThis library is originally designed for the most of scenes of GTD, and long-period backends.\n\n## History\n\n- v0.2.9: security patch for github workflow; fix arch detections in dummy project - affect generating fsm-cxx_config.hh; support c++20 now\n- v0.2.7: rename the cor classes to avoid c++ warnings: timer -\u003e timer_t, ticker -\u003e ticker_t, alarm -\u003e alarm_t\n- v0.2.5: upgrade cmake scripts for better styles, compatibilities, and structures\n- v0.2.3: little improvements for building compatibilities\n- v0.2.1: first public release\n- ? : the plan started\n\n## Guide\n\n### Uses timer\n\nthe one-time timer after a duration (for instance `1us`):\n\n```cpp\nvoid test_timer() {\n    using namespace std::literals::chrono_literals;\n\n    ticker::pool::conditional_wait_for_int count{1};\n    auto t = ticker::timer_t\u003c\u003e::get();\n    t-\u003eafter(1us)\n            .on([\u0026count] {\n                auto now = ticker::chrono::now();\n                ticker::pool::cw_setter cws(count);\n                printf(\"  - after [%02d]: %s\\n\", count.val(), ticker::chrono::format_time_point(now).c_str());\n            })\n            .build();\n\n    printf(\"count.wait()\\n\");\n    count.wait_for(); // wait_for(2s) or wait()\n    // t.clear();\n    printf(\"end of %s\\n\", __FUNCTION_NAME__);\n}\n```\n\n`at()`, `in()` are the synonyms of `after(...)`.\n\n### Uses ticker\n\nruns a ticker after 1us, and stop it once 16 times tick repeated:\n\n```cpp\nvoid test_timer() {\n    using namespace std::literals::chrono_literals;\n\n    ticker::pool::conditional_wait_for_int count{16};\n    auto t = ticker::ticker_t\u003c\u003e::get();\n    t-\u003eevery(1us)\n            .on([\u0026count]() {\n                // auto now = ticker::chrono::now();\n                ticker::pool::cw_setter cws(count);\n                printf(\"  - every [%02d]: %s\\n\", count.val(), ticker::chrono::format_time_point().c_str());\n            })\n            .build();\n\n    count.wait(); // wait_for(2s) or wait()\n}\n```\n\n`interval()` could be used instead of `every()`.\n\n### alarm\n\n`class ticker::alarm` provides the periodical job running mechanism. It could be used in a GTD app perfectly.\n\nA simple demo is:\n\n```cpp\nvoid test_alarm() {\n    using namespace std::literals::chrono_literals;\n    \n    ticker::pool::conditional_wait_for_int count2{4};\n    ticker::alarm_t\u003c\u003e::super::get()\n            -\u003eevery_month(3)\n            .on([\u0026count2] {\n                auto now = ticker::chrono::now();\n                ticker::pool::cw_setter cws(count2);\n                printf(\"  - alarm [%02d]: %s\\n\", count2.val(), ticker::chrono::format_time_point(now).c_str());\n            })\n            .build();\n    printf(\"end of %s\\n\", __FUNCTION_NAME__);\n}\n```\n\n`ticker::alarm::loop_for(anchors, day_offset, how_many_times, repeat_count)` enables the full functions with Anchors enumerated variables:\n\n```cpp\n    enum class anchors {\n        Nothing,\n\n        Month,       // 'offset' (1..31, -1..-31) day every month; with 'ordinal' times\n        TwoMonth,    // 'offset' day every two month\n        Quarter,     // 'offset' quarter day every quarter\n        FourMonth,   //\n        FiveMonth,   //\n        SixMonth,    // 'offset' day every half a year\n        SevenMonth,  //\n        EightMonth,  // eight\n        NineMonth,   //\n        TenMonth,    // ten\n        ElevenMonth, //\n        Year,        // 'offset' day every year, this month; with 'ordinal' times\n\n        FirstThirdOfMonth,  // 'offset' (0..9, -1..-10) day 在每一个上旬; // with 'ordinal' times\n        MiddleThirdOfMonth, // 'offset' (0..9, -1..-10) day 在每一个中旬; // with 'ordinal' times\n        LastThirdOfMonth,   // 'offset' (0..9, -1..-10) day 在每一个下旬; // with 'ordinal' times\n\n        DayInYear,   // 'offset' (0-365) day every one year\n        WeekInMonth, // 'offset' (0..5)  week every one month\n        WeekInYear,  // 'offset' (0..51) week every one year\n        Week,        // 'offset' (0..6)  day every one week\n\n        // ...\n    };\n```\n\n## Build Options\n\n### Build with CMake\n\n\u003e 1. gcc 10+: passed\n\u003e 2. clang 12+: passed\n\u003e 3. msvc build tool 16.7.2, 16.8.5 (VS2019 or Build Tool) passed\n\nninja is optional for faster building.\n\n```bash\n# generate the building config\ncmake -B build/\n# build the whole project (with unittest too)\ncmake --build build/\n\n# configure with ninja\ncmake -S . -B build/ -G Ninja\n\n# CTest\ncmake -E chdir build ctest\n\n# install\ncmake --install build/\n# Or:cmake --build build/ --target install\n#\n# Sometimes sudo it:\n#   sudo cmake --build build/ --target install\n# Or:\n#   cmake --install build/ --prefix ./install --strip\n#   sudo cp -R ./install/include/* /usr/local/include/\n#   sudo cp -R ./install/lib/cmake/fsm_cxx /usr/local/lib/cmake/\n```\n\n### Other CMake Options\n\n1. `TICKER_CXX_BUILD_TESTS_EXAMPLES`=OFF\n2. `TICKER_CXX_BUILD_DOCS`=OFF\n3. ...\n\n### CMake Options with C++ Macros\n\n1. `TICKER_CXX_ENABLE_ASSERTIONS`\n2. `TICKER_CXX_ENABLE_PRECONDITION_CHECKS`=ON\n3. `TICKER_CXX_ENABLE_THREAD_POOL_READY_SIGNAL` (always be 1)\n4. `TICKER_CXX_TEST_THREAD_POOL_DBGOUT`\n5. `TICKER_CXX_UNIT_TEST`\n6. `USE_DEBUG`, `USE_DEBUG_MALLOC`\n7. ...\n\n### Macros after include `ticker-def.hh`\n\n1. `_DEBUG`, `DEBUG`\n2. ...\n\n## Thanks to JODL\n\nThanks to [JetBrains](https://www.jetbrains.com/?from=ticker-cxx) for donating product licenses to help develop **ticker-cxx** [![jetbrains](https://gist.githubusercontent.com/hedzr/447849cb44138885e75fe46f1e35b4a0/raw/bedfe6923510405ade4c034c5c5085487532dee4/jetbrains-variant-4.svg)](https://www.jetbrains.com/?from=hedzr/ticker-cxx)\n\n## LICENSE\n\nApache 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhedzr%2Fticker-cxx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhedzr%2Fticker-cxx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhedzr%2Fticker-cxx/lists"}