diff options
author | cjihrig <cjihrig@gmail.com> | 2019-12-03 23:02:49 -0500 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2019-12-06 22:02:47 -0500 |
commit | f446929923d6cfa471721404d9d7f806449d5fe6 (patch) | |
tree | 53f2e904fa5736ea050729f51320dc35c2faeebc /lib | |
parent | 4ec02d5afdad4610b59fbc22ff2279e35120294e (diff) | |
download | android-node-v8-f446929923d6cfa471721404d9d7f806449d5fe6.tar.gz android-node-v8-f446929923d6cfa471721404d9d7f806449d5fe6.tar.bz2 android-node-v8-f446929923d6cfa471721404d9d7f806449d5fe6.zip |
util: add internal sleep() function
PR-URL: https://github.com/nodejs/node/pull/30787
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/internal/util.js | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/internal/util.js b/lib/internal/util.js index 1ff25dbc7d..0a31973918 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -26,7 +26,8 @@ const { getHiddenValue, setHiddenValue, arrow_message_private_symbol: kArrowMessagePrivateSymbolIndex, - decorated_private_symbol: kDecoratedPrivateSymbolIndex + decorated_private_symbol: kDecoratedPrivateSymbolIndex, + sleep: _sleep } = internalBinding('util'); const { isNativeError } = internalBinding('types'); @@ -385,6 +386,17 @@ function once(callback) { }; } +let validateUint32; + +function sleep(msec) { + // Lazy-load to avoid a circular dependency. + if (validateUint32 === undefined) + ({ validateUint32 } = require('internal/validators')); + + validateUint32(msec, 'msec'); + _sleep(msec); +} + module.exports = { assertCrypto, cachedResult, @@ -402,6 +414,7 @@ module.exports = { normalizeEncoding, once, promisify, + sleep, spliceOne, removeColors, |