"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.TransactionStack = void 0;
const util_1 = require("../util");
/**
 * A helper class that organizes the state needed for managing nesting transactions.
 */
class TransactionStack {
    constructor() {
        this.stack = [];
    }
    /**
     * The number of transactions currently ongoing.
     */
    get size() {
        return this.stack.length;
    }
    /**
     * Pushes a new transaction onto the stack. That transaction becomes the current transaction.
     * @param startRevision - the revision of the latest commit when this transaction begins
     * @param repairStore - an optional repair data store for helping with undo or rollback operations
     * @param disposables - an optional collection of disposable data to release after finishing a transaction
     */
    push(startRevision, dispose) {
        this.stack.push({ startRevision, dispose });
    }
    /**
     * Ends the current transaction. Fails if there is currently no ongoing transaction.
     * @returns The revision that the closed transaction began on, and its repair data store if it has one.
     */
    pop() {
        const transaction = this.stack.pop() ?? (0, util_1.fail)("No transaction is currently in progress");
        transaction.dispose();
        return transaction;
    }
}
exports.TransactionStack = TransactionStack;
//# sourceMappingURL=transactionStack.js.map