5.4. Committing a transaction

To commit a transaction with the transaction to commit, run these steps:

  1. Set transaction’s state to committing.

  2. Run the following steps in parallel:

    1. Wait until every item in transaction’s request list is processed.

    2. If transaction’s state is no longer committing, then terminate these steps.

    3. Attempt to write any outstanding changes made by transaction to the database, considering transaction’s durability hint.

    4. If an error occurs while writing the changes to the database, then run abort a transaction with transaction and an appropriate type for the error, for example “[QuotaExceededError](https://heycam.github.io/webidl/#quotaexceedederror)“ or “[UnknownError](https://heycam.github.io/webidl/#unknownerror)[DOMException](https://heycam.github.io/webidl/#idl-DOMException), and terminate these steps.

    5. Queue a task to run these steps:

      1. If transaction is an upgrade transaction, then set transaction’s connection‘s associated database‘s upgrade transaction to null.

      2. Set transaction’s state to finished.

      3. Fire an event named complete at transaction.

        Even if an exception is thrown from one of the event handlers of this event, the transaction is still committed since writing the database changes happens before the event takes places. Only after the transaction has been successfully written is the complete event fired.

      4. If transaction is an upgrade transaction, then let request be the request associated with transaction and set request’s transaction to null.