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(
33
33
private var currentOperations: MutableList <IAppliedOperation > = ArrayList ()
34
34
private val completedChanges: MutableList <OpsAndTree > = ArrayList ()
35
35
private val id: String = branch.getId()
36
+ private var inWriteTransaction = false
36
37
37
38
fun operationApplied (op : IAppliedOperation ) {
38
39
check(canWrite()) { " Only allowed inside a write transaction" }
@@ -84,18 +85,20 @@ class OTBranch(
84
85
85
86
override fun <T > computeWrite (computable : () -> T ): T {
86
87
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 {
92
93
try {
94
+ inWriteTransaction = true
93
95
val result = computable()
94
96
runSynchronized(completedChanges) {
95
97
completedChanges + = OpsAndTree (currentOperations, t.tree)
96
98
}
97
99
result
98
100
} finally {
101
+ inWriteTransaction = false
99
102
currentOperations = ArrayList ()
100
103
}
101
104
}
You can’t perform that action at this time.
0 commit comments