New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

sleep

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sleep - npm Package Compare versions

Comparing version 3.0.1 to 4.0.0

bin/sleep

24

index.js
try {
module.exports = require('./build/Release/node_sleep.node');
} catch (e) {
console.error('sleep: using busy loop fallback');
module.exports = require('./build/Release/node_sleep.node');
module.exports = {
sleep: function(s) {
var e = new Date().getTime() + (s * 1000);
while (new Date().getTime() <= e) {
;
}
},
usleep: function(s) {
var e = new Date().getTime() + (s / 1000);
while (new Date().getTime() <= e) {
;
}
}
};
}
{
"name": "sleep",
"version": "3.0.1",
"main": "index.js",
"name": "sleep",
"version": "4.0.0",
"main": "index.js",
"description": "Add sleep() and usleep() to nodejs",
"homepage": "http://github.com/ErikDubbelboer/node-sleep",
"author": "Erik Dubbelboer <erik@dubbelboer.com>",
"license": "MIT",
"engines" : { "node" : ">=0.4.0" },
"homepage": "http://github.com/ErikDubbelboer/node-sleep",
"author": "Erik Dubbelboer <erik@dubbelboer.com>",
"license": "MIT",
"scripts": {
"test": "mocha"
},
"engines": {
"node": ">=0.4.0"
},
"keywords": [

@@ -16,3 +21,3 @@ "sleep",

"type": "git",
"url": "https://github.com/ErikDubbelboer/node-sleep.git"
"url": "https://github.com/ErikDubbelboer/node-sleep.git"
},

@@ -22,3 +27,12 @@ "dependencies": {

},
"devDependencies": {
"mocha": "^3.0.2"
},
"bin": {
"sleep": "./bin/sleep",
"sleepuv": "./bin/sleep",
"usleep": "./bin/sleep",
"usleepuv": "./bin/sleep"
},
"gypfile": true
}

@@ -18,4 +18,14 @@ sleep

You can also install this as global dependency:
npm install -g
sleep 1
usleep 1000
On unices or when you have already installed `sleep` and `usleep`, this
installation will not override those. You can instead then use the CLI by
running `sleepuv 1` and `usleepuv 1000`.
[1]: http://linux.die.net/man/3/sleep
[2]: http://linux.die.net/man/3/usleep

@@ -1,12 +0,58 @@

/* globals describe, it */
var sleep = require('./');
var assert = require('assert');
console.log('sleeping for 1 seconds...');
sleep.sleep(1);
console.log('done');
function assertApproxEqual(val1, val2) {
var epsilon = 5; // we require accuracy to the nearest N millisecond
var diff = Math.abs(val1 - val2);
assert.ok(diff <= epsilon);
}
describe('sleep', function () {
it('works for normal input', function () {
var sleepTime = 1;
var start = new Date();
sleep.sleep(sleepTime);
var end = new Date();
assertApproxEqual(end - start, sleepTime * 1000);
});
console.log('sleeping for 2000000 microseconds (2 seconds)');
sleep.usleep(2000000);
console.log('done');
it('works for zero', function () {
var sleepTime = 0;
var start = new Date();
sleep.sleep(sleepTime);
var end = new Date();
assertApproxEqual(end - start, sleepTime * 1000);
});
it('does not allow negative numbers', function () {
assert.throws(function () {
sleep.sleep(-1);
});
});
});
describe('usleep', function () {
it('works for values smaller than a second', function () {
var sleepTime = 30;
var start = new Date();
sleep.usleep(sleepTime);
var end = new Date();
assertApproxEqual(end - start, sleepTime / 1000);
});
it('works for values larger than a second', function () {
this.timeout(4000); // necessary for mocha to not complain
var sleepTime = 3000000;
var start = new Date();
sleep.usleep(sleepTime);
var end = new Date();
assertApproxEqual(end - start, sleepTime / 1000);
});
it('does not allow negative numbers', function () {
assert.throws(function () {
sleep.usleep(-100);
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc