feat: v1.1.4
This commit is contained in:
25
utils/logger.js
Normal file
25
utils/logger.js
Normal 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
34
utils/queue.js
Normal 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);
|
||||
}
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user