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();  // 请求完成后处理下一个请求
    }
}

支持与分享

如果这篇文章对你有帮助,欢迎分享给更多人或者给予支持!

评论

欢迎来到我的博客!