diff options
| author | Vaxry <43317083+vaxerski@users.noreply.github.com> | 2024-04-07 03:31:51 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-07 03:31:51 +0100 |
| commit | f2a848cbcc41f29fb62ee67aef95136ae1a650da (patch) | |
| tree | 6af50d58aa94fbb48880694a76f6edb79fa370ed /src/managers/eventLoop/EventLoopTimer.hpp | |
| parent | 9f1604e4b0afec40cfa9bc095d6613a7f749b2c1 (diff) | |
core: Event loop rework (#5466)
* Event loop rework
* revert missed
Diffstat (limited to 'src/managers/eventLoop/EventLoopTimer.hpp')
| -rw-r--r-- | src/managers/eventLoop/EventLoopTimer.hpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/managers/eventLoop/EventLoopTimer.hpp b/src/managers/eventLoop/EventLoopTimer.hpp new file mode 100644 index 00000000..8865d29f --- /dev/null +++ b/src/managers/eventLoop/EventLoopTimer.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include <chrono> +#include <functional> +#include <optional> + +class CEventLoopTimer { + public: + CEventLoopTimer(std::optional<std::chrono::system_clock::duration> timeout, std::function<void(std::shared_ptr<CEventLoopTimer> self, void* data)> cb_, void* data_); + + // if not specified, disarms. + // if specified, arms. + void updateTimeout(std::optional<std::chrono::system_clock::duration> timeout); + + void cancel(); + bool passed(); + + float leftUs(); + + bool cancelled(); + // resets expires + void call(std::shared_ptr<CEventLoopTimer> self); + + private: + std::function<void(std::shared_ptr<CEventLoopTimer> self, void* data)> cb; + void* data = nullptr; + std::optional<std::chrono::system_clock::time_point> expires; + bool wasCancelled = false; +}; |
