summaryrefslogtreecommitdiffstats
path: root/debian/tests/test_modules/atomic-sleep
diff options
context:
space:
mode:
Diffstat (limited to 'debian/tests/test_modules/atomic-sleep')
-rw-r--r--debian/tests/test_modules/atomic-sleep/LICENSE22
-rw-r--r--debian/tests/test_modules/atomic-sleep/index.js38
-rw-r--r--debian/tests/test_modules/atomic-sleep/package.json37
3 files changed, 97 insertions, 0 deletions
diff --git a/debian/tests/test_modules/atomic-sleep/LICENSE b/debian/tests/test_modules/atomic-sleep/LICENSE
new file mode 100644
index 0000000..d1d8849
--- /dev/null
+++ b/debian/tests/test_modules/atomic-sleep/LICENSE
@@ -0,0 +1,22 @@
+The MIT License (MIT)
+Copyright (c) 2020 David Mark Clements
+
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
+OR OTHER DEALINGS IN THE SOFTWARE.
+
diff --git a/debian/tests/test_modules/atomic-sleep/index.js b/debian/tests/test_modules/atomic-sleep/index.js
new file mode 100644
index 0000000..fbfc8b2
--- /dev/null
+++ b/debian/tests/test_modules/atomic-sleep/index.js
@@ -0,0 +1,38 @@
+'use strict'
+
+/* global SharedArrayBuffer, Atomics */
+
+if (typeof SharedArrayBuffer !== 'undefined' && typeof Atomics !== 'undefined') {
+ const nil = new Int32Array(new SharedArrayBuffer(4))
+
+ function sleep (ms) {
+ // also filters out NaN, non-number types, including empty strings, but allows bigints
+ const valid = ms > 0 && ms < Infinity
+ if (valid === false) {
+ if (typeof ms !== 'number' && typeof ms !== 'bigint') {
+ throw TypeError('sleep: ms must be a number')
+ }
+ throw RangeError('sleep: ms must be a number that is greater than 0 but less than Infinity')
+ }
+
+ Atomics.wait(nil, 0, 0, Number(ms))
+ }
+ module.exports = sleep
+} else {
+
+ function sleep (ms) {
+ // also filters out NaN, non-number types, including empty strings, but allows bigints
+ const valid = ms > 0 && ms < Infinity
+ if (valid === false) {
+ if (typeof ms !== 'number' && typeof ms !== 'bigint') {
+ throw TypeError('sleep: ms must be a number')
+ }
+ throw RangeError('sleep: ms must be a number that is greater than 0 but less than Infinity')
+ }
+ const target = Date.now() + Number(ms)
+ while (target > Date.now()){}
+ }
+
+ module.exports = sleep
+
+}
diff --git a/debian/tests/test_modules/atomic-sleep/package.json b/debian/tests/test_modules/atomic-sleep/package.json
new file mode 100644
index 0000000..cfdf200
--- /dev/null
+++ b/debian/tests/test_modules/atomic-sleep/package.json
@@ -0,0 +1,37 @@
+{
+ "name": "atomic-sleep",
+ "version": "1.0.0",
+ "description": "Zero CPU overhead, zero dependency, true event-loop blocking sleep",
+ "main": "index.js",
+ "scripts": {
+ "test": "tap -R classic- -j1 test",
+ "lint": "standard",
+ "ci": "npm run lint && npm test"
+ },
+ "keywords": [
+ "sleep",
+ "pause",
+ "wait",
+ "performance",
+ "atomics"
+ ],
+ "engines": {
+ "node": ">=8.0.0"
+ },
+ "author": "David Mark Clements (@davidmarkclem)",
+ "license": "MIT",
+ "devDependencies": {
+ "standard": "^14.3.1",
+ "tap": "^14.10.6",
+ "tape": "^4.13.2"
+ },
+ "dependencies": {},
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/davidmarkclements/atomic-sleep.git"
+ },
+ "bugs": {
+ "url": "https://github.com/davidmarkclements/atomic-sleep/issues"
+ },
+ "homepage": "https://github.com/davidmarkclements/atomic-sleep#readme"
+}