mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-14 13:41:05 +00:00
Update std.js
This commit is contained in:
parent
a2678b1ab4
commit
cfb434d1c0
38
lib/std.js
38
lib/std.js
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user