mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-03-12 00:45:14 +00:00
Update task.js
This commit is contained in:
parent
eacecd580b
commit
7874e2e07b
18
lib/task.js
18
lib/task.js
|
@ -1,5 +1,5 @@
|
|||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// Task API (Async implementation in WSH)
|
||||
// Task API (Time-sharing based `async` implementation in WSH.js)
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var Task = function(id, f, params) {
|
||||
|
@ -14,6 +14,8 @@ 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 {
|
||||
|
@ -72,7 +74,15 @@ var TaskQueue = function() {
|
|||
console.error("TaskQueue.then: " + e.message);
|
||||
}
|
||||
};
|
||||
this.lastId = 0;
|
||||
this.run = function() {
|
||||
while(this._keepalive) {
|
||||
this.next();
|
||||
sleep(100);
|
||||
}
|
||||
};
|
||||
this.stop = function() {
|
||||
this._keepalive = false;
|
||||
};
|
||||
};
|
||||
|
||||
exports.createQueue = function() {
|
||||
|
@ -106,3 +116,7 @@ exports.nextTask = function(q) {
|
|||
console.error("nextTask exception: " + e.message);
|
||||
}
|
||||
};
|
||||
|
||||
exports.run = function(q) {
|
||||
q.run();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user