a fun bot for the hc slack
1export default class Queue {
2 private jobs: (() => void)[] = [];
3 private isProcessing = false;
4
5 enqueue(job: () => void) {
6 this.jobs.push(job);
7 if (!this.isProcessing) {
8 this.processQueue();
9 }
10 }
11
12 private processQueue() {
13 if (this.jobs.length > 0) {
14 const job = this.jobs.shift();
15 if (job) {
16 this.isProcessing = true;
17 job();
18 this.isProcessing = false;
19 this.processQueue();
20 }
21 }
22 }
23}