Skip to content

Commit

Permalink
updated Queue/Main.js
Browse files Browse the repository at this point in the history
  • Loading branch information
GHostload committed Feb 14, 2024
1 parent 39539cf commit 2918f16
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions Queue/Main.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
class Queue {
constructor() {
this.queue = []
this.queue = [];
this.processing = false;
}

addJob(job) {
this.queue.push(job)
this.bumpQueue()
this.queue.push(job);
if (!this.processing) {
this.processQueue();
}
}

bumpQueue() {
if (this.processing) return
const job = this.queue.shift()
if (!job) return
const cb = () => {
this.processing = false
this.bumpQueue()
processQueue() {
if (this.processing || this.queue.length === 0) {
return;
}
this.processing = true
job(cb)

const job = this.queue.shift();
this.processing = true;

const callback = () => {
this.processing = false;
this.processQueue();
};

job(callback);
}
}

module.exports = Queue
module.exports = Queue;

0 comments on commit 2918f16

Please sign in to comment.