Added AsyncFunction class

This commit is contained in:
Namhyeon Go 2022-02-24 17:13:31 +09:00
parent 07245f89cf
commit caa57b91e4
4 changed files with 32 additions and 10 deletions

6
app.js
View File

@ -98,7 +98,13 @@ var console = {
// after calling echo // after calling echo
if (['error', 'info', 'warn'].indexOf(type) > -1 && typeof this._echoCallback === "function") { if (['error', 'info', 'warn'].indexOf(type) > -1 && typeof this._echoCallback === "function") {
try {
this._echoCallback(params); this._echoCallback(params);
} catch (e) {
if (typeof WScript !== "undefined") {
WScript.echo(" * Exception of _echoCallback:", e.message);
}
}
} }
}, },
assert: function(assertion) { assert: function(assertion) {

View File

@ -213,6 +213,10 @@ function includeFile(FN) {
eval(fileData); eval(fileData);
} }
function appendFile(FN, content, charset) {
return writeFile(FN, readFile(FN, charset) + content, charset);
}
exports.fileExists = fileExists; exports.fileExists = fileExists;
exports.folderExists = folderExists; exports.folderExists = folderExists;
exports.fileGet = fileGet; exports.fileGet = fileGet;
@ -224,3 +228,4 @@ exports.createFolder = createFolder;
exports.deleteFolder = deleteFolder; exports.deleteFolder = deleteFolder;
exports.deleteFile = deleteFile; exports.deleteFile = deleteFile;
exports.includeFile = includeFile; exports.includeFile = includeFile;
exports.appendFile = appendFile;

View File

@ -306,6 +306,16 @@ function StdEventableObject() {
}; };
}; };
function AsyncFunction(f) {
this.f = f;
this.run = function() {
sleep(1, this.f);
};
this.runSynchronously = function() {
return this.f();
};
};
global.GetResource = GetResource; global.GetResource = GetResource;
global.sleep = sleep; global.sleep = sleep;
global.repeat = repeat; global.repeat = repeat;
@ -314,6 +324,7 @@ global.range = range;
global.CHR = CHR; global.CHR = CHR;
global.splitLn = splitLn; global.splitLn = splitLn;
global.addslashes = addslashes; global.addslashes = addslashes;
global.AsyncFunction = AsyncFunction;
exports.VERSIONINFO = "Standard Lib (std.js) version 0.4"; exports.VERSIONINFO = "Standard Lib (std.js) version 0.4";
exports.global = global; exports.global = global;

View File

@ -39,8 +39,8 @@ var WebsocketObject = function() {
this.binPath, this.binPath,
"-n1", "-n1",
"-t", "-t",
"--ping-timeout", //"--ping-timeout",
1, //1,
uri, uri,
"<", "<",
FN FN