1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.Queue = void 0;
|
7 |
|
8 |
|
9 |
|
10 | class Queue {
|
11 | |
12 |
|
13 |
|
14 | _queue_ = [];
|
15 |
|
16 | |
17 |
|
18 |
|
19 | constructor() {}
|
20 |
|
21 | |
22 |
|
23 |
|
24 |
|
25 |
|
26 | get size() {
|
27 | return this._queue_.length;
|
28 | }
|
29 |
|
30 | |
31 |
|
32 |
|
33 | clear() {
|
34 | this._queue_ = [];
|
35 | }
|
36 |
|
37 | |
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | push(handler, priority = 0) {
|
44 | const queue = this._queue_;
|
45 | let index = 0;
|
46 | for (let i = queue.length; i--;) {
|
47 | if (queue[i].priority < priority) {
|
48 | index = i + 1;
|
49 | break;
|
50 | }
|
51 | }
|
52 | queue.splice(index, 0, {
|
53 | priority,
|
54 | handler
|
55 | });
|
56 | }
|
57 |
|
58 | |
59 |
|
60 |
|
61 |
|
62 |
|
63 | pop() {
|
64 | const entry = this._queue_.pop();
|
65 | return entry ? entry.handler : null;
|
66 | }
|
67 |
|
68 | |
69 |
|
70 |
|
71 |
|
72 |
|
73 | shift() {
|
74 | const entry = this._queue_.shift();
|
75 | return entry ? entry.handler : null;
|
76 | }
|
77 |
|
78 | |
79 |
|
80 |
|
81 | async run() {
|
82 | for (;;) {
|
83 | const entry = this.pop();
|
84 | if (!entry) {
|
85 | break;
|
86 | }
|
87 |
|
88 |
|
89 | await entry();
|
90 | }
|
91 | }
|
92 | }
|
93 | exports.Queue = Queue;
|
94 |
|
\ | No newline at end of file |