Update task.js

This commit is contained in:
Namhyeon Go 2022-09-22 17:02:41 +09:00 committed by GitHub
parent 7fa00324ee
commit e4cce764b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,5 @@
//////////////////////////////////////////////////////////////////////////////////
// Task API (Time-sharing based `async`, `setTimeout`, `setInterval`, `Promise` implementation in WSH.js)
// Task API (Time-sharing based `async`, `setTimeout`, `setInterval`, implementation in WSH.js)
/////////////////////////////////////////////////////////////////////////////////
/* // example:
@ -49,7 +49,7 @@ function Task(f, params) {
this.callCount = 0;
return this;
};
};
}
function TaskQueue() {
this._task = null;
@ -146,11 +146,11 @@ function TaskQueue() {
this.stop = function() {
this._keepalive = false;
};
};
}
function createTaskQueue() {
return new TaskQueue();
};
}
function createTask(f, params, failTask) {
try {
@ -158,9 +158,9 @@ function createTask(f, params, failTask) {
} catch(e) {
console.error("createTask exception: " + e.message);
}
};
}
function putTask = function(q, task, delay) {
function putTask(q, task, delay) {
try {
if (q instanceof TaskQueue && task instanceof Task) {
return q.put(task, delay);
@ -168,23 +168,23 @@ function putTask = function(q, task, delay) {
} catch(e) {
console.error("putTask exception: " + e.message);
}
};
}
function nextTask = function(q) {
function nextTask(q) {
try {
return q.next();
} catch(e) {
console.error("nextTask exception: " + e.message);
}
};
}
function run = function(q) {
function run(q) {
q.run();
};
}
function stop = function(q) {
function stop(q) {
q.stop();
};
}
////////////////////////////////////////////////////
// START Global functions
@ -205,36 +205,9 @@ function setInterval(f, delay) {
__taskQueue__.put(task);
}
function Promise(executor) {
this.length = 1;
this.executor = executor;
this.all = function(iterable) {
// todo
};
this.race = function(iterable) {
// todo
};
this.reject = function(reason) {
// todo
};
this.resolve = function(reason) {
// todo
};
this.then = function(successCallback, failureCallback) {
// todo
};
this.catch = function(failureCallback) {
// todo
};
this.executor(this.resolve, this.reject);
}
exports.__taskQueue__ = __taskQueue__;
exports.setTimeout = setTimeout;
exports.setInterval = setInterval;
exports.Promise = Promise;
////////////////////////////////////////////////////
// END Global functions
@ -250,6 +223,6 @@ exports.nextTask = nextTask;
exports.run = run;
exports.stop = stop;
exports.VERSIONINFO = "Task Module (task.js) version 0.2.1";
exports.VERSIONINFO = "Task Module (task.js) version 0.2.2";
exports.global = global;
exports.require = require;