var SyncTaskManager = /** @class */ (function () {
    function SyncTaskManager(fn) {
        var _this = this;
        this.tasks = [];
        this.isDestroy = false;
        this.isScheduling = false;
        this.schedule = function () {
            _this.isScheduling = true;
            var task = _this.tasks.shift();
            if (task && !_this.isDestroy) {
                _this.fn(task).finally(function () {
                    if (_this.tasks.length > 0) {
                        window.requestAnimationFrame(_this.schedule);
                    }
                    else {
                        _this.isScheduling = false;
                    }
                });
            }
        };
        this.fn = fn;
    }
    SyncTaskManager.prototype.destroy = function () {
        this.isDestroy = true;
    };
    SyncTaskManager.prototype.addTask = function (evt) {
        this.tasks.push(evt);
        if (!this.isScheduling) {
            this.schedule();
        }
    };
    return SyncTaskManager;
}());
export { SyncTaskManager };
