Update std.js

This commit is contained in:
Namhyeon Go 2022-02-08 18:09:29 +09:00 committed by GitHub
parent a2678b1ab4
commit cfb434d1c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -72,26 +72,52 @@ global.GetResource = function(ResourceName) {
// [lib/std] the time of `sleep()' function is not accuracy #34 // [lib/std] the time of `sleep()' function is not accuracy #34
global.sleep = function(ms, callback) { global.sleep = function(ms, callback) {
var handler = null;
var cur = Date.now(); var cur = Date.now();
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();
*/
if (typeof(callback) === "function") WScript.Sleep(ms);
if (typeof callback === "function")
callback() callback()
; ;
} else if (typeof(window) !== "undefined") { } else if (typeof window !== "undefined") {
if (typeof(callback) === "function") if (typeof callback === "function")
setTimeout(callback, ms) handler = setTimeout(callback, ms);
; ;
} }
return end; return { 'ms': end, 'handler': handler };
};
global.repeat = function(ms, callback) {
var handler = null;
var cur = Date.now();
var end = cur + ms;
if (typeof WScript !== "undefined") {
while (cur < end) {
sleep(callback().ms);
cur = Date.now();
}
end = Date.now();
} else if (typeof window !== "undefined") {
if (typeof callback === "function")
handler = setInterval(callback, ms)
;
}
return { 'ms': end, 'handler': handler };
}; };
global.CHR = function(ord) { global.CHR = function(ord) {