| 81 | |
| 82 | private: |
| 83 | void ExecuteLoop() { |
| 84 | auto shared_this = this->shared_from_this(); |
| 85 | executor_.ExecuteAt(next_call_time_, [shared_this, planned_time = next_call_time_]() { |
| 86 | if (shared_this->IsCancelled()) { |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | // Skip current execution if timer was reset or restarted |
| 91 | if (planned_time != shared_this->next_call_time_) { |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | shared_this->ExecuteTask(); |
| 96 | |
| 97 | auto now = shared_this->executor_.Now(); |
| 98 | shared_this->next_call_time_ = std::chrono::time_point_cast<std::chrono::system_clock::duration>( |
| 99 | shared_this->next_call_time_ + shared_this->period_); |
| 100 | |
| 101 | // If now is ahead of the next call time, skip some times. |
| 102 | if (shared_this->next_call_time_ < now) { |
| 103 | if (shared_this->period_ == std::chrono::nanoseconds::zero()) { |
| 104 | shared_this->next_call_time_ = now; |
| 105 | } else { |
| 106 | auto now_ahead = now - shared_this->next_call_time_; |
| 107 | auto skip_count = 1 + ((now_ahead - std::chrono::nanoseconds(1)) / shared_this->period_); |
| 108 | shared_this->next_call_time_ = std::chrono::time_point_cast<std::chrono::system_clock::duration>( |
| 109 | shared_this->next_call_time_ + (skip_count * shared_this->period_)); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | shared_this->ExecuteLoop(); |
| 114 | }); |
| 115 | } |
| 116 | |
| 117 | private: |
| 118 | TaskType task_; |
nothing calls this directly
no test coverage detected