-
Notifications
You must be signed in to change notification settings - Fork 934
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEBUG_USE_MICROSECONDS=Y DEBUG=* node ./examples/node/useMicroseconds.js
- Loading branch information
Showing
8 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"targets": [ | ||
{ | ||
"target_name": "module", | ||
"sources": [ "./src/module.c" ] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* node-gyp configure build | ||
* | ||
* DEBUG_USE_MICROSECONDS=Y DEBUG=* node ./examples/node/useMicroseconds.js | ||
* DEBUG=* node ./examples/node/useMicroseconds.js | ||
*/ | ||
|
||
const debug = require('../../')('use:µs'); | ||
|
||
debug('the ∆ is') | ||
debug('the ∆ is') | ||
debug('the ∆ is') | ||
debug('the ∆ is') | ||
debug('the ∆ is') | ||
debug('the ∆ is') | ||
debug('the ∆ is') | ||
debug('the ∆ is') | ||
setTimeout(() => debug('the ∆ is'), 11000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include <node_api.h> /* n-api */ | ||
#include <sys/time.h> /* gettimeofday, timeval (for timestamp in microseconds) */ | ||
|
||
long long int now () { | ||
struct timeval t_us; | ||
long long int us; | ||
|
||
if (!gettimeofday(&t_us, NULL)) { | ||
us = ((long long int) t_us.tv_sec) * 1000000ll + | ||
(long long int) t_us.tv_usec; | ||
} | ||
else return -1ll; | ||
|
||
return us; | ||
} | ||
|
||
napi_value MyFunction (napi_env env, napi_callback_info info) { | ||
napi_status status; | ||
|
||
/* Convert to JS Number the current time in microseconds. | ||
*/ | ||
long long int number = now(); | ||
napi_value myNumber; | ||
status = napi_create_int64(env, number, &myNumber); | ||
if (status != napi_ok) { | ||
napi_throw_error(env, NULL, "Unable to create return value"); | ||
} | ||
|
||
return myNumber; | ||
} | ||
|
||
napi_value Init (napi_env env, napi_value exports) { | ||
napi_status status; | ||
napi_value fn; | ||
|
||
status = napi_create_function(env, NULL, 0, MyFunction, NULL, &fn); | ||
if (status != napi_ok) { | ||
napi_throw_error(env, NULL, "Unable to wrap native function"); | ||
} | ||
|
||
status = napi_set_named_property(env, exports, "gettimeofday", fn); | ||
if (status != napi_ok) { | ||
napi_throw_error(env, NULL, "Unable to populate exports"); | ||
} | ||
|
||
return exports; | ||
} | ||
|
||
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters