File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed
model-datastructure/src/commonMain/kotlin/org/modelix/model/operations Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ class OTBranch(
3333 private var currentOperations: MutableList <IAppliedOperation > = ArrayList ()
3434 private val completedChanges: MutableList <OpsAndTree > = ArrayList ()
3535 private val id: String = branch.getId()
36+ private var inWriteTransaction = false
3637
3738 fun operationApplied (op : IAppliedOperation ) {
3839 check(canWrite()) { " Only allowed inside a write transaction" }
@@ -84,18 +85,20 @@ class OTBranch(
8485
8586 override fun <T > computeWrite (computable : () -> T ): T {
8687 checkNotEDT()
87- return if (canWrite()) {
88- // Already in a transaction. Just append changes to the active one.
89- branch.computeWrite(computable)
90- } else {
91- branch.computeWriteT { t ->
88+ return branch.computeWriteT { t ->
89+ // canWrite() cannot be used as the condition, because that may statically return true (see TreePointer)
90+ if (inWriteTransaction) {
91+ computable()
92+ } else {
9293 try {
94+ inWriteTransaction = true
9395 val result = computable()
9496 runSynchronized(completedChanges) {
9597 completedChanges + = OpsAndTree (currentOperations, t.tree)
9698 }
9799 result
98100 } finally {
101+ inWriteTransaction = false
99102 currentOperations = ArrayList ()
100103 }
101104 }
You can’t perform that action at this time.
0 commit comments