scheduler: add thread_sleep, use const& param
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-01-17 04:42:59 +01:00
parent 146bf14d68
commit 62f31c1436
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
2 changed files with 6 additions and 2 deletions

View File

@ -8,7 +8,7 @@ namespace accumulator {
class EventScheduler {
public:
virtual void schedule(std::chrono::milliseconds delay_ms) = 0;
virtual void schedule(const std::chrono::milliseconds& delay_ms) = 0;
EventScheduler(const EventScheduler&) = delete;
EventScheduler& operator=(const EventScheduler&) = delete;

View File

@ -4,6 +4,7 @@
#include "event_scheduler.h"
#include <chrono>
#include <thread>
namespace fortuna {
namespace accumulator {
@ -15,7 +16,10 @@ private:
public:
EventSchedulerImpl();
void schedule(std::chrono::milliseconds delay_ms) override {}
void schedule(const std::chrono::milliseconds& delay_ms) override {
auto now{std::chrono::system_clock::now()};
std::this_thread::sleep_until(now + delay_ms);
}
};
} // namespace accumulator