Update task.js

This commit is contained in:
Namhyeon Go 2021-06-23 11:13:32 +09:00 committed by GitHub
parent eacecd580b
commit 7874e2e07b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();
};