0
0
0
js 队列
2026-11-21
2026-11-21
export default class RequestQueue {
constructor() {
this.queue = [];
this.processing = false;
}
// 添加请求到队列
addRequest(request) {
this.queue.push(request);
this.processQueue().then(r => {
});
}
// 处理队列中的请求
async processQueue() {
if (this.processing || this.queue.length === 0) return;
this.processing = true;
const request = this.queue.shift(); // 获取队列中的第一个请求
await request(); // 执行请求
this.processing = false;
await this.processQueue(); // 请求完成后处理下一个请求
}
}