mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-11-27 18:11:20 +00:00
Update task.js
This commit is contained in:
parent
19957e12b7
commit
939121321e
19
lib/task.js
19
lib/task.js
|
|
@ -20,13 +20,19 @@ var Task = function(f, params) {
|
||||||
this.f = f;
|
this.f = f;
|
||||||
this.params = params;
|
this.params = params;
|
||||||
this.nextTask = null;
|
this.nextTask = null;
|
||||||
|
this.failTask = null;
|
||||||
this.when = 0;
|
this.when = 0;
|
||||||
this.delay = 0;
|
this.delay = 0;
|
||||||
this.callCount = 0;
|
this.callCount = 0;
|
||||||
|
|
||||||
this.setNextTask = function(task) {
|
this.setNextTask = function(task) {
|
||||||
this.nextTask = task;
|
this.nextTask = task;
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
this.setFailTask = function(task) {
|
||||||
|
this.failTask = task;
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.setWhen = function(when) {
|
this.setWhen = function(when) {
|
||||||
this.when = when;
|
this.when = when;
|
||||||
return this;
|
return this;
|
||||||
|
|
@ -41,6 +47,7 @@ var Task = function(f, params) {
|
||||||
};
|
};
|
||||||
this.resetCount = function() {
|
this.resetCount = function() {
|
||||||
this.callCount = 0;
|
this.callCount = 0;
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -48,6 +55,7 @@ var TaskQueue = function() {
|
||||||
this._task = null;
|
this._task = null;
|
||||||
this._keepalive = true;
|
this._keepalive = true;
|
||||||
this.queue = [];
|
this.queue = [];
|
||||||
|
|
||||||
this.put = function(task, delay) {
|
this.put = function(task, delay) {
|
||||||
var now = new Date();
|
var now = new Date();
|
||||||
|
|
||||||
|
|
@ -102,6 +110,11 @@ var TaskQueue = function() {
|
||||||
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));
|
||||||
console.error("task.params: " + typeof(task.params));
|
console.error("task.params: " + typeof(task.params));
|
||||||
|
|
||||||
|
// 태스크 개별 오류 처리
|
||||||
|
if (task.failTask) {
|
||||||
|
this.put(task.failTask, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
|
@ -139,9 +152,9 @@ exports.createTaskQueue = function() {
|
||||||
return new TaskQueue();
|
return new TaskQueue();
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.createTask = function(f, params) {
|
exports.createTask = function(f, params, failTask) {
|
||||||
try {
|
try {
|
||||||
return new Task(f, params);
|
return (new Task(f, params)).setFailTask(failTask);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.error("createTask exception: " + e.message);
|
console.error("createTask exception: " + e.message);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user