12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- import { __awaiter } from "tslib";
- class Queue {
- constructor() {
- 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);
- }
- else {
- this.start = node;
- }
- if (autoRun) {
- this.startRun();
- }
- }
- startRun() {
- if (this.status === "waiting") {
- this.run();
- }
- }
- run() {
- return __awaiter(this, void 0, void 0, function* () {
- if (this.start) {
- this.status = "running";
- const self = this.start.getSelf();
- this.start = this.start.getNext();
- const res = yield self.run();
- if (res === false) {
- this.status = "waiting";
- }
- else {
- this.run();
- }
- }
- else {
- this.status = "waiting";
- }
- });
- }
- }
- class Node {
- constructor(self) {
- this.self = self;
- }
- getSelf() {
- return this.self;
- }
- setPrev(prev) {
- this.prev = prev;
- if (prev) {
- prev.next = this;
- }
- }
- setNext(next) {
- this.next = next;
- if (next) {
- next.prev = this;
- }
- }
- getPrev() {
- return this.prev;
- }
- getNext() {
- return this.next;
- }
- }
- export { Queue };
|