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