Skip to content

Commit

Permalink
Refactor Sleep into sleep.h
Browse files Browse the repository at this point in the history
  • Loading branch information
ofrobots committed Feb 9, 2018
1 parent 2678eaf commit 8ec4423
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ LINT_SOURCES = \
test/cpp/returnvalue.cpp \
test/cpp/setcallhandler.cpp \
test/cpp/settemplate.cpp \
test/cpp/sleeph.h \
test/cpp/strings.cpp \
test/cpp/symbols.cpp \
test/cpp/threadlocal.cpp \
Expand Down
4 changes: 2 additions & 2 deletions test/cpp/asyncresource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
********************************************************************/

#include <nan.h>
#include <unistd.h>
#include "sleep.h"

using namespace Nan; // NOLINT(build/namespaces)

Expand All @@ -30,7 +30,7 @@ class DelayRequest : public AsyncResource {

void Delay(uv_work_t* req) {
DelayRequest *delay_request = static_cast<DelayRequest*>(req->data);
sleep(delay_request->milliseconds / 1000);
Sleep(delay_request->milliseconds);
}

void AfterDelay(uv_work_t* req, int status) {
Expand Down
5 changes: 1 addition & 4 deletions test/cpp/asyncworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
* MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
********************************************************************/

#ifndef _WIN32
#include <unistd.h>
#define Sleep(x) usleep((x)*1000)
#endif
#include "sleep.h"
#include <nan.h>

using namespace Nan; // NOLINT(build/namespaces)
Expand Down
4 changes: 2 additions & 2 deletions test/cpp/callbackcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
********************************************************************/

#include <nan.h>
#include <unistd.h>
#include "sleep.h"

using namespace Nan; // NOLINT(build/namespaces)

Expand All @@ -28,7 +28,7 @@ class DelayRequest : public AsyncResource {

void Delay(uv_work_t* req) {
DelayRequest *delay_request = static_cast<DelayRequest*>(req->data);
sleep(delay_request->milliseconds / 1000);
Sleep(delay_request->milliseconds);
}

void AfterDelay(uv_work_t* req, int status) {
Expand Down
14 changes: 14 additions & 0 deletions test/cpp/sleep.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*********************************************************************
* NAN - Native Abstractions for Node.js
*
* Copyright (c) 2017 NAN contributors
*
* MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
********************************************************************/

#ifndef _WIN32
#include <unistd.h>
#define Sleep(x) usleep((x)*1000)
#endif


0 comments on commit 8ec4423

Please sign in to comment.