{"id":15801674,"url":"https://github.com/nawaz1991/timedeventqueue","last_synced_at":"2025-04-21T08:31:52.210Z","repository":{"id":201057541,"uuid":"617371916","full_name":"nawaz1991/TimedEventQueue","owner":"nawaz1991","description":"TimedEventQueue is a C++17 template class for managing and scheduling events based on their associated timestamps.","archived":false,"fork":false,"pushed_at":"2023-03-22T18:08:39.000Z","size":5,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-06T01:41:15.346Z","etag":null,"topics":["cpp","event","priority-queue","timed-events"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nawaz1991.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-03-22T08:54:48.000Z","updated_at":"2024-08-29T02:41:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"1057797e-0d29-48c7-b630-b85162bbc9c3","html_url":"https://github.com/nawaz1991/TimedEventQueue","commit_stats":null,"previous_names":["nawaz1991/timedeventqueue"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nawaz1991%2FTimedEventQueue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nawaz1991%2FTimedEventQueue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nawaz1991%2FTimedEventQueue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nawaz1991%2FTimedEventQueue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nawaz1991","download_url":"https://codeload.github.com/nawaz1991/TimedEventQueue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250023535,"owners_count":21362418,"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":["cpp","event","priority-queue","timed-events"],"created_at":"2024-10-05T01:40:22.078Z","updated_at":"2025-04-21T08:31:51.981Z","avatar_url":"https://github.com/nawaz1991.png","language":"C++","readme":"Timed Event Queue\n==============\n`TimedEventQueue` is a C++17 template class for managing and scheduling events based on their associated timestamps. It\nprovides a simple and efficient way to handle time-based events in your C++ applications. This class is particularly\nuseful for scenarios such as scheduling tasks, timeouts, or any other event that needs to be triggered at a specific\ntime.\n\nThe `TimedEventQueue` class uses a separate worker thread to manage event expiration and invokes a user-provided\ncallback function when an event's timestamp expires. It is designed with thread-safety in mind, allowing you to add,\nremove, and update events from multiple threads simultaneously.\n\n### Features\n\n- Schedule events with associated timestamps and values\n- Efficiently handles event expiration using a separate worker thread\n- Thread-safe implementation for adding, removing, and updating events\n- User-provided callback function for custom event expiration behavior\n- Supports C++17 standard\n\n### Requirements\n\n- C++17 compiler\n- Standard C++ library\n\n### Installation\n\nSimply include the timeEventQueue.hpp header file in your project.\n\n### Usage\n\nTo use `TimedEventQueue`, follow these steps:\n\n1. Include the `timeEventQueue.hpp` header file in your project.\n2. Derive your own class from `TimedEventQueue`, providing a template argument for the event value type.\n3. Implement the `onTimestampExpire` function in your derived class, defining the custom behavior to be executed when an\n   event expires.\n4. Instantiate your derived class and use the member functions to add, remove, and update events.\n\n### Step-by-step Example\n\nAn example program demonstrating the usage of `TimedEventQueue` can be found here:\n\n#### Example Program\n\n~~~cpp\n#include \"TimedEventQueue.hpp\"\n#include \u003ciostream\u003e\n\nclass MyTimedEventQueue : public TimedEventQueue\u003cint\u003e {\nprotected:\n    void onTimestampExpire(const TIMESTAMP \u0026timestamp, const int \u0026value) override {\n        std::cout \u003c\u003c \"Timestamp expired: \"\n                  \u003c\u003c std::chrono::duration_cast\u003cstd::chrono::seconds\u003e(timestamp.time_since_epoch()).count()\n                  \u003c\u003c \" with value: \" \u003c\u003c value \u003c\u003c std::endl;\n    }\n};\n\nint main() {\n    MyTimedEventQueue myTimedEventQueue;\n\n    auto now = TIME::now();\n    myTimedEventQueue.addEvent(now + std::chrono::seconds(3), 1);\n    myTimedEventQueue.addEvent(now + std::chrono::seconds(1), 2);\n    myTimedEventQueue.addEvent(now + std::chrono::seconds(2), 3);\n    myTimedEventQueue.addEvent(now + std::chrono::seconds(4), 4);\n    myTimedEventQueue.removeEvent(2); // remove using value\n    myTimedEventQueue.removeEvent(now + std::chrono::seconds(2)); // remove using timestamp\n    myTimedEventQueue.updateValue(now + std::chrono::seconds(4), 5); //update using value\n    myTimedEventQueue.updateTimestamp(now + std::chrono::seconds(10), 1); //update using timestamp\n    std::this_thread::sleep_for(std::chrono::seconds(6)); // sleep for 6 seconds\n    myTimedEventQueue.stop(); // finally stop and the entry with (updated value) 10 will not be printed as that event will occur after the stop\n\n    return 0;\n}\n~~~\n\n##### Compile\n\n~~~shell\ng++ -std=c++17 -pthread myTimedEventQueue.cpp -o myTimedEventQueue\n~~~\n\n##### Run\n\n~~~shell\n./myTimedEventQueue\n~~~\n\n### API Reference\n\nThe TimedEventQueue class provides the following public member functions:\n\n- `addEvent(const TIMESTAMP \u0026timestamp, const T \u0026value)`: Adds an event with the specified timestamp and value to the\n  queue.\n- `removeEvent(const T \u0026value)`: Removes the event with the specified value from the queue.\n- `removeEvent(const TIMESTAMP \u0026timestamp)`: Removes the event with the specified timestamp from the queue.\n- `updateValue(const TIMESTAMP \u0026timestamp, const T \u0026value)`: Updates the value associated with the specified timestamp\n  in the queue.\n- `updateTimestamp(const TIMESTAMP \u0026timestamp, const T \u0026value)`: Updates the timestamp associated with the specified\n  value in the queue.\n- `stop()`: Stops the worker thread and cleans up resources.\n\n### License\n\nThis project is open-source and available under the MIT License.\n\n### Author\n\n[Muhammad Nawaz](mailto:m.nawaz2003@gmail.com)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnawaz1991%2Ftimedeventqueue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnawaz1991%2Ftimedeventqueue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnawaz1991%2Ftimedeventqueue/lists"}