mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-10-19 23:30:56 +00:00
Update task.js
This commit is contained in:
parent
2fe4601ad9
commit
a6ef912c85
15
lib/task.js
15
lib/task.js
|
@ -2,8 +2,7 @@
|
||||||
// Task API (Time-sharing based `async` implementation in WSH.js)
|
// Task API (Time-sharing based `async` implementation in WSH.js)
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
var Task = function(id, f, params) {
|
var Task = function(f, params)
|
||||||
this.id = id;
|
|
||||||
this.f = f;
|
this.f = f;
|
||||||
this.params = params;
|
this.params = params;
|
||||||
this.nextTask = null;
|
this.nextTask = null;
|
||||||
|
@ -15,13 +14,11 @@ var Task = function(id, f, params) {
|
||||||
var TaskQueue = function() {
|
var TaskQueue = function() {
|
||||||
this._task = null;
|
this._task = null;
|
||||||
this._keepalive = true;
|
this._keepalive = true;
|
||||||
this.lastId = 0;
|
|
||||||
this.queue = [];
|
this.queue = [];
|
||||||
this.put = function(task) {
|
this.put = function(task) {
|
||||||
try {
|
try {
|
||||||
this._task = task;
|
this._task = task;
|
||||||
this.queue.push(this._task);
|
this.queue.push(this._task);
|
||||||
this.lastId++;
|
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.error("TaskQueue.put exception: " + e.message);
|
console.error("TaskQueue.put exception: " + e.message);
|
||||||
}
|
}
|
||||||
|
@ -90,20 +87,18 @@ exports.createTaskQueue = function() {
|
||||||
return new TaskQueue();
|
return new TaskQueue();
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.buildTask = function(q, f, params) {
|
exports.createTask = function(f, params) {
|
||||||
try {
|
try {
|
||||||
if (q instanceof TaskQueue) {
|
return new Task(f, params);
|
||||||
return new Task(q.lastId, f, params);
|
|
||||||
}
|
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.error("makeTask exception: " + e.message);
|
console.error("createTask exception: " + e.message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.putTask = function(q, f, params) {
|
exports.putTask = function(q, f, params) {
|
||||||
try {
|
try {
|
||||||
if (q instanceof TaskQueue) {
|
if (q instanceof TaskQueue) {
|
||||||
return q.put(new Task(q.lastId, f, params));
|
return q.put(new Task(f, params));
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.error("putTask exception: " + e.message);
|
console.error("putTask exception: " + e.message);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user