{"id":13424638,"url":"https://github.com/ortfero/timetable","last_synced_at":"2026-01-16T17:41:06.423Z","repository":{"id":49784150,"uuid":"382965356","full_name":"ortfero/timetable","owner":"ortfero","description":"C++17 one-header library to invoke something periodically or at the specified time","archived":false,"fork":false,"pushed_at":"2024-08-28T09:18:13.000Z","size":114,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-26T23:55:35.130Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ortfero.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-04T23:11:00.000Z","updated_at":"2024-08-28T09:18:17.000Z","dependencies_parsed_at":"2024-08-28T10:52:06.260Z","dependency_job_id":null,"html_url":"https://github.com/ortfero/timetable","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ortfero%2Ftimetable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ortfero%2Ftimetable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ortfero%2Ftimetable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ortfero%2Ftimetable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ortfero","download_url":"https://codeload.github.com/ortfero/timetable/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243775907,"owners_count":20346283,"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":[],"created_at":"2024-07-31T00:00:57.234Z","updated_at":"2026-01-16T17:41:06.413Z","avatar_url":"https://github.com/ortfero.png","language":"C++","readme":"# timetable\nC++17 one-header library to invoke something periodically or at specified time\n\n## Synopsis\n\n```cpp\nnamespace timetable {\n\n    struct context {\n        virtual ~context() { }\n    };\n    \n\n    template\u003ctypename L = detail::spinlock\u003e\n    class scheduler {\n    public:\n        using handler = std::function\u003cvoid (std::chrono::system_clock::time_point, context* context)\u003e;\n\n        scheduler(duration const\u0026 granularity = std::chrono::milliseconds{500});\n        \n        scheduler(scheduler const\u0026) = delete;\n        scheduler\u0026 operator = (scheduler const\u0026) = delete;\n        ~scheduler();\n\n        template\u003ctypename F\u003e\n        task_id schedule_from_time(time_point time_at,\n                                   duration const\u0026 interval,\n                                   F\u0026\u0026 handler,\n                                   std::unique_ptr\u003ccontext\u003e context = nullptr);\n        \n        template\u003ctypename F\u003e\n        task_id schedule_from_now(duration const\u0026 interval,\n                                  F\u0026\u0026 handler,\n                                  std::unique_ptr\u003ccontext\u003e context = nullptr);\n        \n        \n        bool unschedule(task_id tid) noexcept;\n      \n        template\u003ctypename F\u003e\n        task_id schedule_daily_at(duration const\u0026 time_of_day,\n                                  F\u0026\u0026 handler,\n                                  std::unique_ptr\u003ccontext\u003e context = nullptr);\n        \n        template\u003ctypename F\u003e\n        task_id schedule_every_hour(F\u0026\u0026 handler,\n                                    std::unique_ptr\u003ccontext\u003e context = nullptr);\n        \n        template\u003ctypename F\u003e\n        task_id schedule_every_minute(F\u0026\u0026 handler,\n                                      std::unique_ptr\u003ccontext\u003e context = nullptr);\n        \n        template\u003ctypename F\u003e\n        task_id schedule_every_second(F\u0026\u0026 handler,\n                                      std::unique_ptr\u003ccontext\u003e context = nullptr);\n                \n        template\u003ctypename F\u003e\n        task_id schedule_once(time_point time_at,\n                              F\u0026\u0026 handler,\n                              std::unique_ptr\u003ccontext\u003e context = nullptr);\n        \n        void pass(); // pass scheduling\n        void run(); // run in a separate thread\n        void stop();\n    }; // scheduler\n    \n} // namespace timetable\n```\n\n## Snippets\n\n\n### Set scheduler precision\n\n```cpp\n#include \u003cchrono\u003e\n#include \u003ctimetable/timetable.hpp\u003e\n...\nauto scheduler = timetable::scheduler{std::chrono::milliseconds{300}};\n```\n\n### Run task periodically from now\n\n```cpp\n#include \u003ccstdio\u003e\n#include \u003cchrono\u003e\n#include \u003cthread\u003e\n#include \u003ctimetable/timetable.hpp\u003e\n\n\nint main() {\n    auto scheduler = timetable::scheduler{};\n    scheduler.schedule_from_now(std::chrono::seconds{1},\n        [](std::chrono::system_clock::time_point){ std::puts(\"one second\"); });\n    scheduler.run();\n    std::this_thread::sleep_for(std::chrono::seconds{10});\n    scheduler.stop();\n    return 0;\n}\n```\n\n### Run task daily at specified time\n\n```cpp\n#include \u003ccstdio\u003e\n#include \u003cchrono\u003e\n#include \u003cthread\u003e\n#include \u003ctimetable/timetable.hpp\u003e\n\nint main() {\n    auto scheduler = timetable::scheduler{};\n    using namespace std::chrono;\n    auto const at = hours{13} + minutes{13} + seconds{13};\n    scheduler.schedule_daily_at(at,\n        [](std::chrono::system_clock::time_point){ std::puts(\"now 13:13:13 utc\"); });\n    scheduler.run();\n    std::this_thread::sleep_for(minutes{5});\n    scheduler.stop();\n    return 0;\n}\n```\n\n\n### Remove scheduled task\n```cpp\n#include \u003cchrono\u003e\n...\nauto scheduler = timetable::scheduler{};\n\nauto const task_id = scheduler.schedule_from_now(std::chrono::hours{1},\n    [](std::chrono::system_clock::time_point){ std::puts(\"1 hour passed\"); });\nscheduler.unschedule(task_id);\n```\n","funding_links":[],"categories":["Scheduling"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fortfero%2Ftimetable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fortfero%2Ftimetable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fortfero%2Ftimetable/lists"}