Update std.js

This commit is contained in:
Namhyeon Go 2022-10-10 12:01:24 -06:00 committed by GitHub
parent b3e4ddc8d1
commit 565175f63c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -90,15 +90,13 @@ function sleep(ms, callback) {
var end = cur + ms; var end = cur + ms;
if (typeof WScript !== "undefined") { if (typeof WScript !== "undefined") {
/*
while (cur < end) { while (cur < end) {
//WScript.Sleep(1); WScript.Sleep(1);
cur = Date.now(); cur = Date.now();
} }
end = Date.now(); end = Date.now();
*/
WScript.Sleep(ms); //WScript.Sleep(ms);
if (typeof callback === "function") if (typeof callback === "function")
callback() callback()
; ;
@ -111,7 +109,7 @@ function sleep(ms, callback) {
return { 'ms': end, 'handler': handler }; return { 'ms': end, 'handler': handler };
}; };
function repeat(target, callback, onError) { function repeat(target, callback, onError, onNextInterval) {
switch (typeof target) { switch (typeof target) {
case "number": case "number":
case "boolean": 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(); cur = Date.now();
} }
end = Date.now(); end = Date.now();