From 565175f63cbd946b2313f319ee0ac88dfebfce7e Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Mon, 10 Oct 2022 12:01:24 -0600 Subject: [PATCH] Update std.js --- lib/std.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/std.js b/lib/std.js index bd8f759..1a42aa1 100644 --- a/lib/std.js +++ b/lib/std.js @@ -90,15 +90,13 @@ function sleep(ms, callback) { var end = cur + ms; if (typeof WScript !== "undefined") { - /* while (cur < end) { - //WScript.Sleep(1); + WScript.Sleep(1); cur = Date.now(); } end = Date.now(); - */ - - WScript.Sleep(ms); + + //WScript.Sleep(ms); if (typeof callback === "function") callback() ; @@ -111,7 +109,7 @@ function sleep(ms, callback) { return { 'ms': end, 'handler': handler }; }; -function repeat(target, callback, onError) { +function repeat(target, callback, onError, onNextInterval) { switch (typeof target) { case "number": case "boolean": @@ -143,6 +141,18 @@ function repeat(target, callback, onError) { } } } + + // if use the next interval function + if (typeof onNextInterval === "function") { + var nextInterval = onNextInterval(); + if (typeof nextInterval === "number") { + var nextEnd = cur + nextInterval; + while (cur < nextEnd) { + WScript.Sleep(1); + cur = Date.now(); + } + } + } cur = Date.now(); } end = Date.now();