mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-06-02 06:57:02 +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)
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user