mirror of
https://github.com/gnh1201/welsonjs.git
synced 2024-11-26 15:31:42 +00:00
Update task.js
This commit is contained in:
parent
1e3b0dc47e
commit
23a3e27058
14
lib/task.js
14
lib/task.js
|
@ -22,6 +22,7 @@ var Task = function(f, params) {
|
|||
this.nextTask = null;
|
||||
this.when = 0;
|
||||
this.delay = 0;
|
||||
this.callCount = 0;
|
||||
this.setNextTask = function(task) {
|
||||
this.nextTask = task;
|
||||
};
|
||||
|
@ -34,6 +35,10 @@ var Task = function(f, params) {
|
|||
this.delay = delay;
|
||||
return this;
|
||||
};
|
||||
this.upCallCount = function() {
|
||||
this.callCount++;
|
||||
return this;
|
||||
};
|
||||
};
|
||||
|
||||
var TaskQueue = function() {
|
||||
|
@ -67,13 +72,14 @@ var TaskQueue = function() {
|
|||
var i = delta.indexOf(Math.min.apply(Math, delta));
|
||||
var d = this.queue[i].when + this.queue[i].delay - now.getTime();
|
||||
if (i > -1 && d <= 0) {
|
||||
console.log("Task", i, d);
|
||||
task = this.queue.splice(i, 1)[0];
|
||||
}
|
||||
}
|
||||
} catch(e) {
|
||||
console.error("TaskQueue.get: " + e.message);
|
||||
}
|
||||
|
||||
|
||||
return task;
|
||||
};
|
||||
this.next = function() {
|
||||
|
@ -84,10 +90,11 @@ var TaskQueue = function() {
|
|||
|
||||
if (task != null) {
|
||||
try {
|
||||
result = task.f.apply(null, [task].concat(task.params));
|
||||
result = task.f.apply(Task, [task].concat(task.params));
|
||||
if (task.nextTask != null) {
|
||||
this.put(task.nextTask, task.nextTask.delay);
|
||||
}
|
||||
task.upCallCount(); // 호출 횟수 기록
|
||||
} catch (e) {
|
||||
console.error("Task exception: " + e.message);
|
||||
console.error("task.f: " + typeof(task.f));
|
||||
|
@ -164,6 +171,9 @@ exports.stop = function(q) {
|
|||
q.stop();
|
||||
};
|
||||
|
||||
exports.Task = Task;
|
||||
exports.TaskQueue = TaskQueue;
|
||||
|
||||
exports.VERSIONINFO = "Task Module (task.js) version 0.2";
|
||||
exports.global = global;
|
||||
exports.require = require;
|
||||
|
|
Loading…
Reference in New Issue
Block a user