|
@@ -4,13 +4,13 @@ class Queue {
|
|
|
this.status = "waiting";
|
|
|
}
|
|
|
append(item, autoRun = true) {
|
|
|
- var _a;
|
|
|
const node = new Node(item);
|
|
|
- if (this.start) {
|
|
|
- (_a = this.start) === null || _a === void 0 ? void 0 : _a.setNext(node);
|
|
|
+ if (!this.current || !this.end) {
|
|
|
+ this.current = this.end = node;
|
|
|
}
|
|
|
else {
|
|
|
- this.start = node;
|
|
|
+ this.end.setNext(node);
|
|
|
+ this.end = node;
|
|
|
}
|
|
|
if (autoRun) {
|
|
|
this.startRun();
|
|
@@ -23,11 +23,13 @@ class Queue {
|
|
|
}
|
|
|
run() {
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
- if (this.start) {
|
|
|
+ if (this.current) {
|
|
|
this.status = "running";
|
|
|
- const self = this.start.getSelf();
|
|
|
- this.start = this.start.getNext();
|
|
|
+ const current = this.current;
|
|
|
+ const self = current.getSelf();
|
|
|
+ this.current = this.current.getNext();
|
|
|
const res = yield self.run();
|
|
|
+ current.destroy();
|
|
|
if (res === false) {
|
|
|
this.status = "waiting";
|
|
|
}
|
|
@@ -36,6 +38,7 @@ class Queue {
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
+ this.end = undefined;
|
|
|
this.status = "waiting";
|
|
|
}
|
|
|
});
|
|
@@ -66,5 +69,16 @@ class Node {
|
|
|
getNext() {
|
|
|
return this.next;
|
|
|
}
|
|
|
+ destroy() {
|
|
|
+ if (this.prev) {
|
|
|
+ this.prev.setNext(null);
|
|
|
+ }
|
|
|
+ if (this.next) {
|
|
|
+ this.next.setPrev(null);
|
|
|
+ }
|
|
|
+ this.prev = null;
|
|
|
+ this.next = null;
|
|
|
+ this.self = undefined;
|
|
|
+ }
|
|
|
}
|
|
|
export { Queue };
|