Comparing version 5.1.1 to 5.2.2
{ | ||
"name": "sleep", | ||
"version": "5.1.1", | ||
"version": "5.2.2", | ||
"main": "index.js", | ||
@@ -27,5 +27,5 @@ "description": "Add sleep() and usleep() to nodejs", | ||
"devDependencies": { | ||
"mocha": "^3.0.2" | ||
"mocha": "^4.0.1" | ||
}, | ||
"gypfile": true | ||
} |
@@ -0,1 +1,4 @@ | ||
[![Build Status](https://travis-ci.org/erikdubbelboer/node-sleep.png?branch=master)](https://travis-ci.org/erikdubbelboer/node-sleep) | ||
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Ferikdubbelboer%2Fnode-sleep.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Ferikdubbelboer%2Fnode-sleep?ref=badge_shield) | ||
sleep | ||
@@ -8,4 +11,21 @@ ===== | ||
**These calls will block execution of all JavaScript by halting Node.js' event loop!** | ||
These calls will block execution of all JavaScript by halting Node.js' event loop! | ||
================================================================================== | ||
Alternative | ||
----------- | ||
When using nodejs `9.3` or higher it's better to use [Atomics.wait](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait) which doesn't require compiling this C++ | ||
module. | ||
The `sleep` and `msleep` functions can be implemented like this: | ||
```js | ||
function msleep(n) { | ||
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, n); | ||
} | ||
function sleep(n) { | ||
msleep(n*1000); | ||
} | ||
``` | ||
If you require `usleep` this module is still required. | ||
Usage | ||
@@ -23,1 +43,5 @@ ----- | ||
[2]: http://linux.die.net/man/3/usleep | ||
## License | ||
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Ferikdubbelboer%2Fnode-sleep.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Ferikdubbelboer%2Fnode-sleep?ref=badge_large) |
14
test.js
/* globals describe, it */ | ||
var sleep = require('./'); | ||
var assert = require('assert'); | ||
var child_process = require('child_process'); | ||
@@ -8,3 +9,5 @@ function assertApproxEqual(val1, val2) { | ||
var diff = Math.abs(val1 - val2); | ||
assert.ok(diff <= epsilon); | ||
if (diff > epsilon) { | ||
assert.fail(diff, epsilon, 'wait was too short', '>'); | ||
} | ||
} | ||
@@ -34,2 +37,11 @@ | ||
}); | ||
it('works with child_process', function () { | ||
var sleepTime = 1; | ||
child_process.exec('echo', function (err, stdout, stderr) { }); | ||
var start = new Date(); | ||
sleep.sleep(sleepTime); | ||
var end = new Date(); | ||
assertApproxEqual(end - start, sleepTime * 1000); | ||
}); | ||
}); | ||
@@ -36,0 +48,0 @@ |
Sorry, the diff of this file is not supported yet
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
8355
89
46
2