

/**
 * 队列执行
 */
export class Queue {
    private isProcessing = false;
    private queue: Array<() => Promise<void>> = [];
    private async processQueue() {
        if (this.isProcessing) return;
        this.isProcessing = true;

        while (this.queue.length > 0) {
            const func = this.queue.shift();
            await func!();
        }

        this.isProcessing = false;
    }

    enqueue(func: () => Promise<void>) {

        this.queue.push(func);
        this.processQueue();
    }


}