-
-
Notifications
You must be signed in to change notification settings - Fork 15
Functions
Namhyeon, Go edited this page Oct 18, 2024
·
8 revisions
JScript does not support the async
and Generator
keywords. So, WelsonJS uses the AsyncFunction
, GeneratorFunction
class made by itself.
var STD = require("lib/std");
function main(args) {
[5, 4, 3, 2, 1].forEach(function(x) {
new AsyncFunction(function() {
sleep(x * 1000);
console.log(x);
}).run();
});
}
exports.main = main;
// You must explicitly specify where to find the function.
AsyncFunction.__filename__ = "program.js";
var STD = require("lib/std");
function onShoutcut(args) {
[5, 4, 3, 2, 1].forEach(function(x) {
sub_01.run();
});
}
var sub_01 = new AsyncFunction(function(args) {
var x = args[0];
sleep(x * 1000);
console.log(x);
});
function main(args) {
// If this is completed, stop with an AsyncFunction.Resolved exception.
AsyncFunction.Initialize(exports, args);
// If it does not try to call an async function.
onShoutcut(args);
}
exports.main = main;
exports.onShoutcut = onShoutcut;
exports.sub_01 = sub_01;
// You must explicitly specify where to find the function.
AsyncFunction.__filename__ = "program.js";
var a = new GeneratorFunction(function(_yield) {
_yield("a");
_yield("b");
_yield("c");
});
console.log(a.next().value);
console.log(a.next().value);
console.log(a.next().value);
This document may contain outdated content. For the latest information, please contact us directly or refer to the webpage below.