Just want to confirm something involving the exper...
# exposed
e
Just want to confirm something involving the experimental coroutine support via
newSuspendedTransaction
. 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:
Copy code
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:
Copy code
newSuspendedTransaction(<http://Dispatchers.IO|Dispatchers.IO>) {
  coroutineScope {
    repeat(5) { 
      // Should I be using suspendedTransactionAsync here?
      launch { someFunctionThatUpdatesRows() }
    }
  }
}
t
Not exactly, you should not share
Transaction
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)
e
Got it, so we just can’t use the same transaction with muiltiple coroutines executing in parallel
👌 1