Skip to content

Commit 48c1ff0

Browse files
authored
refactor: use std::this_thread::sleep_for (#86)
1 parent 9716b8d commit 48c1ff0

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

examples/example_integration.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
#include <iostream>
44
#include <random>
55
#include <thread>
6-
#ifdef _WIN32
7-
#include <Windows.h>
8-
#else
9-
#include <unistd.h>
10-
#endif
116

127
using namespace std;
138
using namespace cly;
@@ -123,7 +118,7 @@ int main() {
123118
// Open a view
124119
std::string viewID = ct.views().openView("Main view", segmentation);
125120

126-
Sleep(2000); // two seconds
121+
std::this_thread::sleep_for(2s);
127122

128123
// Close an opened view
129124
ct.views().closeViewWithID(viewID);

tests/views.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#include "countly.hpp"
22
#include "doctest.h"
3-
#ifdef _WIN32
4-
#include <Windows.h>
5-
#else
6-
#include <unistd.h>
7-
#endif
3+
4+
#include <chrono>
5+
#include <thread>
86

97
using namespace cly;
8+
using namespace std::literals::chrono_literals;
109

1110
/**
1211
* Validate view data.
@@ -65,7 +64,7 @@ TEST_CASE("recording views") {
6564
nlohmann::json s = e["segmentation"].get<nlohmann::json>();
6665
validateViewSegmentation(e, "view1", eid, 0, true, true);
6766

68-
Sleep(3000);
67+
std::this_thread::sleep_for(3s);
6968
ct.views().closeViewWithName("view1");
7069
eventSize++;
7170
CHECK(ct.debugReturnStateOfEQ().size() == eventSize);
@@ -94,7 +93,7 @@ TEST_CASE("recording views") {
9493

9594
validateViewSegmentation(e, "view1", eid, 0, true);
9695

97-
Sleep(2000);
96+
std::this_thread::sleep_for(2s);
9897

9998
ct.views().closeViewWithID(eid);
10099
eventSize++;
@@ -138,7 +137,7 @@ TEST_CASE("recording views") {
138137
CHECK(s["platform"].get<std::string>() == "ubuntu");
139138
CHECK(s["time"].get<std::string>() == "60");
140139

141-
Sleep(3000);
140+
std::this_thread::sleep_for(3s);
142141

143142
ct.views().closeViewWithName("view2");
144143
eventSize++;
@@ -173,7 +172,7 @@ TEST_CASE("recording views") {
173172
CHECK(s["platform"].get<std::string>() == "ubuntu");
174173
CHECK(s["time"].get<std::string>() == "60");
175174

176-
Sleep(1000);
175+
std::this_thread::sleep_for(1s);
177176

178177
ct.views().closeViewWithID(eid);
179178
eventSize++;

0 commit comments

Comments
 (0)