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
4ece56e47e
commit
4382867eb8
20
lib/task.js
20
lib/task.js
|
@ -42,11 +42,21 @@ var TaskQueue = function() {
|
||||||
};
|
};
|
||||||
this.get = function() {
|
this.get = function() {
|
||||||
var task = null;
|
var task = null;
|
||||||
|
var now = new Date().getTime();
|
||||||
|
var delta = now;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (this.queue.length > 0) {
|
if (this.queue.length > 0) {
|
||||||
task = this.queue[0];
|
var k = 0;
|
||||||
this.queue = this.queue.slice(1);
|
for (var i = 0; i < this.queue.length; i++) {
|
||||||
|
var _delta = now - this.queue[i].when;
|
||||||
|
if (delta > _delta) {
|
||||||
|
k = i;
|
||||||
|
delta = _delta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
task = this.queue[k];
|
||||||
|
this.queue = this.queue.splice(k, 1);
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.error("TaskQueue.get: " + e.message);
|
console.error("TaskQueue.get: " + e.message);
|
||||||
|
@ -56,7 +66,7 @@ var TaskQueue = function() {
|
||||||
};
|
};
|
||||||
this.next = function() {
|
this.next = function() {
|
||||||
var result = null;
|
var result = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var task = this.get();
|
var task = this.get();
|
||||||
|
|
||||||
|
@ -66,7 +76,7 @@ var TaskQueue = function() {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Task exception: " + e.message);
|
console.error("Task exception: " + e.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (task.nextTask != null) {
|
if (task.nextTask != null) {
|
||||||
this.put(task.nextTask);
|
this.put(task.nextTask);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user