var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
export class HeadsetChangesQueue {
    static queueHeadsetChanges(fn) {
        return new Promise((resolve, reject) => {
            this.toDoQueue.push({
                fn,
                resolve,
                reject
            });
            if (!this.processingPromise) {
                this.dequeueHeadsetChanges();
            }
        });
    }
    static dequeueHeadsetChanges() {
        return __awaiter(this, void 0, void 0, function* () {
            if (this.processingPromise) {
                return false;
            }
            const item = this.toDoQueue.shift();
            if (!item) {
                return false;
            }
            try {
                this.processingPromise = true;
                const result = yield item.fn();
                item.resolve(result);
            }
            catch (err) {
                item.reject(err);
            }
            finally {
                this.processingPromise = false;
                this.dequeueHeadsetChanges();
            }
        });
    }
    static clearQueue() {
        this.toDoQueue = [];
    }
}
HeadsetChangesQueue.toDoQueue = [];
HeadsetChangesQueue.processingPromise = false;
//# sourceMappingURL=headset-utils.js.map