Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "pch.h"
 
class EventTimer {
 public:
  bool Start() {
    auto now = std::chrono::high_resolution_clock::now();
    if (!_started ||
        std::chrono::duration_cast<std::chrono::microseconds>(now - _startTime).count() >
          _kDurationBetweenSendingEvents) {
      _started = true;
      _startTime = std::chrono::high_resolution_clock::now();
      return true;
    }
 
    return false;
  }
 
 private:
  bool _started = false;
  std::chrono::steady_clock::time_point _startTime;
  constexpr static long long _kDurationBetweenSendingEvents =
    1000 * 50;  // duration in (us). send an Event every 50 ms;
};