feat: v1.1.4

This commit is contained in:
mol
2023-05-31 14:21:33 +08:00
commit 9b8dafefb1
17 changed files with 596 additions and 0 deletions

34
utils/queue.js Normal file
View File

@ -0,0 +1,34 @@
module.exports = class Queue {
constructor() {
this.queue = [];
}
addMethod(method) {
return new Promise((resolve, reject) => {
this.queue.push({ method, resolve, reject });
if (this.queue.length === 1) {
this.executeNext();
}
});
}
async executeNext() {
const { method, resolve, reject } = this.queue[0];
try {
const result = await method();
resolve(result);
} catch (e) {
reject(e);
}
this.queue.shift();
if (this.queue.length > 0) {
setTimeout(() => {
this.executeNext();
}, Math.random() * 1000 + 500);
}
}
};