From f446929923d6cfa471721404d9d7f806449d5fe6 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Tue, 3 Dec 2019 23:02:49 -0500 Subject: util: add internal sleep() function PR-URL: https://github.com/nodejs/node/pull/30787 Reviewed-By: Rich Trott Reviewed-By: Gus Caplan Reviewed-By: Richard Lau --- lib/internal/util.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'lib/internal/util.js') 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, -- cgit v1.2.3