"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HeadsetChangesQueue = void 0;
class HeadsetChangesQueue {
    static queueHeadsetChanges(fn) {
        return new Promise((resolve, reject) => {
            this.toDoQueue.push({
                fn,
                resolve,
                reject
            });
            if (!this.processingPromise) {
                this.dequeueHeadsetChanges();
            }
        });
    }
    static async dequeueHeadsetChanges() {
        if (this.processingPromise) {
            return false;
        }
        const item = this.toDoQueue.shift();
        if (!item) {
            return false;
        }
        try {
            this.processingPromise = true;
            const result = await item.fn();
            item.resolve(result);
        }
        catch (err) {
            item.reject(err);
        }
        finally {
            this.processingPromise = false;
            this.dequeueHeadsetChanges();
        }
    }
    static clearQueue() {
        this.toDoQueue = [];
    }
}
exports.HeadsetChangesQueue = HeadsetChangesQueue;
HeadsetChangesQueue.toDoQueue = [];
HeadsetChangesQueue.processingPromise = false;
//# sourceMappingURL=headset-utils.js.map