mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-02-11 17:34:58 +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
|
||||
global.sleep = function(ms, callback) {
|
||||
var handler = null;
|
||||
|
||||
var cur = Date.now();
|
||||
var end = cur + ms;
|
||||
|
||||
if (typeof(WScript) !== "undefined") {
|
||||
if (typeof WScript !== "undefined") {
|
||||
/*
|
||||
while (cur < end) {
|
||||
//WScript.Sleep(1);
|
||||
cur = Date.now();
|
||||
}
|
||||
end = Date.now();
|
||||
*/
|
||||
|
||||
if (typeof(callback) === "function")
|
||||
WScript.Sleep(ms);
|
||||
if (typeof callback === "function")
|
||||
callback()
|
||||
;
|
||||
} else if (typeof(window) !== "undefined") {
|
||||
if (typeof(callback) === "function")
|
||||
setTimeout(callback, ms)
|
||||
} else if (typeof window !== "undefined") {
|
||||
if (typeof callback === "function")
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user