blob: 8865d29fae3a8405734aae3ca4b01694680fb74a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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;
};
|