Skip to content

Commit 2b893ac

Browse files
committed
Add sleep method to Clock
1 parent f12f7e2 commit 2b893ac

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

src/engine/internal/clock.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0
22

3+
#include <thread>
4+
35
#include "clock.h"
46

57
using namespace libscratchcpp;
@@ -24,3 +26,8 @@ std::chrono::system_clock::time_point Clock::currentSystemTime() const
2426
{
2527
return std::chrono::system_clock::now();
2628
}
29+
30+
void Clock::sleep(const std::chrono::milliseconds &time) const
31+
{
32+
std::this_thread::sleep_for(time);
33+
}

src/engine/internal/clock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class Clock : public IClock
1919
std::chrono::steady_clock::time_point currentSteadyTime() const override;
2020
std::chrono::system_clock::time_point currentSystemTime() const override;
2121

22+
void sleep(const std::chrono::milliseconds &time) const override;
23+
2224
private:
2325
static std::shared_ptr<Clock> m_instance;
2426
};

src/engine/internal/iclock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class IClock
1414

1515
virtual std::chrono::steady_clock::time_point currentSteadyTime() const = 0;
1616
virtual std::chrono::system_clock::time_point currentSystemTime() const = 0;
17+
18+
virtual void sleep(const std::chrono::milliseconds &time) const = 0;
1719
};
1820

1921
} // namespace libscratchcpp

test/mocks/clockmock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ class ClockMock : public IClock
1010
public:
1111
MOCK_METHOD(std::chrono::steady_clock::time_point, currentSteadyTime, (), (const, override));
1212
MOCK_METHOD(std::chrono::system_clock::time_point, currentSystemTime, (), (const, override));
13+
14+
MOCK_METHOD(void, sleep, (const std::chrono::milliseconds &time), (const, override));
1315
};

0 commit comments

Comments
 (0)