Evan R.
10/16/2019, 3:03 PMnewSuspendedTransaction
. The documentation states that we shouldn’t share a transaction between multiple threads due to undefined behavior, so are we not allowed to call other suspending functions within a newSuspendedTransaction()
block given when the suspended transaction resumes it may resume on another thread?
For example:
newSuspendedTransaction(<http://Dispatchers.IO|Dispatchers.IO>) {
val result1 = myTable.select { ... }.toList()
// newSuspendedTransaction suspends here
callSomeSuspendingFunction()
// newSuspendedTransaction resumes, possibly in another thread??
val result2 = myTable.select {...}.toList()
}
Or:
newSuspendedTransaction(<http://Dispatchers.IO|Dispatchers.IO>) {
coroutineScope {
repeat(5) {
// Should I be using suspendedTransactionAsync here?
launch { someFunctionThatUpdatesRows() }
}
}
}
tapac
10/16/2019, 4:40 PMTransaction
instance between threads what means if you launch 5 parallel jobs which will make some modification within same transaction you could face unpredicitible result.
It's the same as shared state (https://kotlinlang.org/docs/reference/coroutines/shared-mutable-state-and-concurrency.html)Evan R.
10/16/2019, 4:45 PM