Update task.js

This commit is contained in:
Namhyeon Go 2021-06-23 11:57:38 +09:00 committed by GitHub
parent 2fe4601ad9
commit a6ef912c85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,8 +2,7 @@
// Task API (Time-sharing based `async` implementation in WSH.js)
/////////////////////////////////////////////////////////////////////////////////
var Task = function(id, f, params) {
this.id = id;
var Task = function(f, params)
this.f = f;
this.params = params;
this.nextTask = null;
@ -15,13 +14,11 @@ var Task = function(id, f, params) {
var TaskQueue = function() {
this._task = null;
this._keepalive = true;
this.lastId = 0;
this.queue = [];
this.put = function(task) {
try {
this._task = task;
this.queue.push(this._task);
this.lastId++;
} catch(e) {
console.error("TaskQueue.put exception: " + e.message);
}
@ -90,20 +87,18 @@ exports.createTaskQueue = function() {
return new TaskQueue();
};
exports.buildTask = function(q, f, params) {
exports.createTask = function(f, params) {
try {
if (q instanceof TaskQueue) {
return new Task(q.lastId, f, params);
}
return new Task(f, params);
} catch(e) {
console.error("makeTask exception: " + e.message);
console.error("createTask exception: " + e.message);
}
};
exports.putTask = function(q, f, params) {
try {
if (q instanceof TaskQueue) {
return q.put(new Task(q.lastId, f, params));
return q.put(new Task(f, params));
}
} catch(e) {
console.error("putTask exception: " + e.message);