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

25
utils/logger.js Normal file
View File

@ -0,0 +1,25 @@
const dayjs = require('dayjs');
function info(message) {
console.log(`${dayjs().format('YYYY-MM-DD hh:mm:ss')}【消息】${message}`);
}
function warning(message) {
console.log(`${dayjs().format('YYYY-MM-DD hh:mm:ss')}【警告】${message}`);
}
function error(message) {
console.log(`${dayjs().format('YYYY-MM-DD hh:mm:ss')}【错误】${message}`);
}
function logger(message) {
info(message);
}
logger.prototype.warning = warning;
logger.prototype.info = info;
logger.prototype.error = error;
module.exports = logger;

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);
}
}
};