2024-04-07 03:31:51 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
|
#include <functional>
|
|
|
|
|
#include <optional>
|
|
|
|
|
|
2024-06-11 17:17:45 +02:00
|
|
|
#include "../../helpers/memory/Memory.hpp"
|
2024-05-05 17:16:00 +01:00
|
|
|
|
2024-04-07 03:31:51 +01:00
|
|
|
class CEventLoopTimer {
|
|
|
|
|
public:
|
2024-05-05 17:16:00 +01:00
|
|
|
CEventLoopTimer(std::optional<std::chrono::system_clock::duration> timeout, std::function<void(SP<CEventLoopTimer> self, void* data)> cb_, void* data_);
|
2024-04-07 03:31:51 +01:00
|
|
|
|
|
|
|
|
// 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
|
2024-05-05 17:16:00 +01:00
|
|
|
void call(SP<CEventLoopTimer> self);
|
2024-04-07 03:31:51 +01:00
|
|
|
|
|
|
|
|
private:
|
2024-05-05 17:16:00 +01:00
|
|
|
std::function<void(SP<CEventLoopTimer> self, void* data)> cb;
|
|
|
|
|
void* data = nullptr;
|
|
|
|
|
std::optional<std::chrono::system_clock::time_point> expires;
|
|
|
|
|
bool wasCancelled = false;
|
2024-04-07 03:31:51 +01:00
|
|
|
};
|