mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 12:47:08 +00:00
Remove old queue implementation
This commit is contained in:
@@ -1,52 +0,0 @@
|
|||||||
const Queue = require('./queue');
|
|
||||||
|
|
||||||
// Inspired by:
|
|
||||||
// https://stackoverflow.com/questions/53540348/js-async-await-tasks-queue#53540586
|
|
||||||
|
|
||||||
class ActionsQueue extends Queue {
|
|
||||||
|
|
||||||
constructor (items = []) {
|
|
||||||
super(items);
|
|
||||||
|
|
||||||
this.pending = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
enqueue (action) {
|
|
||||||
return new Promise ((resolve, reject) => {
|
|
||||||
super.enqueue({ action, resolve, reject });
|
|
||||||
this.dequeue();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async dequeue () {
|
|
||||||
|
|
||||||
if (this.pending) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const item = super.dequeue();
|
|
||||||
|
|
||||||
if (!item) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
this.pending = true;
|
|
||||||
|
|
||||||
const result = await item.action(this);
|
|
||||||
|
|
||||||
this.pending = false;
|
|
||||||
item.resolve(result);
|
|
||||||
} catch (err) {
|
|
||||||
this.pending = false;
|
|
||||||
item.reject(err);
|
|
||||||
} finally {
|
|
||||||
this.dequeue();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = ActionsQueue;
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
|
|
||||||
module.exports = {
|
|
||||||
Queue: require('./queue'),
|
|
||||||
ActionsQueue: require('./actions-queue')
|
|
||||||
};
|
|
||||||
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
|
|
||||||
class Queue {
|
|
||||||
|
|
||||||
constructor (items = []) {
|
|
||||||
this.items = items;
|
|
||||||
}
|
|
||||||
|
|
||||||
enqueue (item) {
|
|
||||||
this.items.push(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
dequeue () {
|
|
||||||
return this.items.shift();
|
|
||||||
}
|
|
||||||
|
|
||||||
length () {
|
|
||||||
return this.items.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = Queue;
|
|
||||||
Reference in New Issue
Block a user