what is difference between `suspendedTransactionAs...
# exposed
a
what is difference between
suspendedTransactionAsync()
and
newSuspendedTransaction()
i know one of them return Deferred and other the direct value. But i see that both of them suspend at the time of call, i.e. if `suspendedTransactionAsync()`suspends at the time of call then what is use of
await()
on the deferred? Like
CoroutineScope.async()
doesn't suspend at the time of call but rather when
await()
is called on that right, so what's difference b/w them(transactions)?
a
@tapac its not explained there perfectly, why does suspendedTransactionAsync() suspends, again the library is complex so cannot go one by one to calls... Async things should not suspend since they just launch coroutine, whereas it should suspend when we are waiting for the result in await(), i don't understand its behavior
t
It suspend on a dispatcher thread and shouldn't block your main thread execution.
a
@tapac why does it suspend?
t
From documentation:
Because Exposed uses JDBC-api to interact with databases that was designed in an era of blocking apis.
Please note what such code remains blocking (as it still uses JDBC) and you should not try to share a transaction between multiple threads as it will lead to undefined behaviour.
a
Copy code
val job = async(<http://Dispatchers.IO|Dispatchers.IO>) { // it does not suspend here at this line
    // suspendable tasks
}

hob.await() //it does suspend here and should
t
It works just like this when you use
suspendedTransactionAsync
a
Compiler shows it suspends
Ohh got it, it suspend for scope creation not for async execution, its confusing since no definition of methods.
Anyways thanks for your valueable time 🙂
👌 2
387 Views