Skip to content

Commit eb442c8

Browse files
committed
test: use uv_sleep() where possible
1 parent 5815e3e commit eb442c8

File tree

2 files changed

+4
-27
lines changed

2 files changed

+4
-27
lines changed

test/addons/async-hello-world/binding.cc

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
#include <v8.h>
33
#include <uv.h>
44

5-
#if defined _WIN32
6-
#include <windows.h>
7-
#else
8-
#include <unistd.h>
9-
#endif
10-
115

126
struct async_req {
137
uv_work_t req;
@@ -21,11 +15,7 @@ struct async_req {
2115
void DoAsync(uv_work_t* r) {
2216
async_req* req = reinterpret_cast<async_req*>(r->data);
2317
// Simulate CPU intensive process...
24-
#if defined _WIN32
25-
Sleep(1000);
26-
#else
27-
sleep(1);
28-
#endif
18+
uv_sleep(1000);
2919
req->output = req->input * 2;
3020
}
3121

test/node-api/test_async/test_async.c

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
#include <assert.h>
22
#include <stdio.h>
33
#include <node_api.h>
4+
#include <uv.h>
45
#include "../../js-native-api/common.h"
56

6-
#if defined _WIN32
7-
#include <windows.h>
8-
#else
9-
#include <unistd.h>
10-
#endif
11-
127
// this needs to be greater than the thread pool size
138
#define MAX_CANCEL_THREADS 6
149

@@ -23,11 +18,7 @@ static carrier the_carrier;
2318
static carrier async_carrier[MAX_CANCEL_THREADS];
2419

2520
static void Execute(napi_env env, void* data) {
26-
#if defined _WIN32
27-
Sleep(1000);
28-
#else
29-
sleep(1);
30-
#endif
21+
uv_sleep(1000);
3122
carrier* c = (carrier*)(data);
3223

3324
assert(c == &the_carrier);
@@ -130,11 +121,7 @@ static void CancelComplete(napi_env env, napi_status status, void* data) {
130121
}
131122

132123
static void CancelExecute(napi_env env, void* data) {
133-
#if defined _WIN32
134-
Sleep(1000);
135-
#else
136-
sleep(1);
137-
#endif
124+
uv_sleep(1000);
138125
}
139126

140127
static napi_value TestCancel(napi_env env, napi_callback_info info) {

0 commit comments

Comments
 (0)