parent
9f1604e4b0
commit
f2a848cbcc
7 changed files with 281 additions and 7 deletions
29
src/managers/eventLoop/EventLoopTimer.hpp
Normal file
29
src/managers/eventLoop/EventLoopTimer.hpp
Normal file
|
|
@ -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;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue