https://kotlinlang.org logo
#ktor
Title
# ktor
w

waltermcq

05/02/2020, 9:28 PM
if JDBC is blocking, what is the benefit of using coroutines for async database calls through exposed w/ postgres?
d

Dominaezzz

05/02/2020, 10:23 PM
Multithreaded database calls?
n

napperley

05/03/2020, 1:43 AM
If the blocking DB stuff is done in a coroutine then only the coroutine is blocked, and any other coroutines that are running will remain unaffected (not blocked).
m

mp

05/03/2020, 9:33 PM
blocking i/o blocks the thread, which will also block any coroutines that might be waiting to run on that thread.
That's why you should wrap your blocking IO calls with
withContext(<http://Dispatchers.IO|Dispatchers.IO>)
(or other coroutine builders as needed)
w

waltermcq

05/04/2020, 1:01 AM
@mp how does this compare with using
newSuspendedTransaction(<http://Dispatchers.IO|Dispatchers.IO>)
as seen here: https://github.com/JetBrains/Exposed/wiki/Transactions#working-with-coroutines
m

mp

05/04/2020, 1:01 AM
Probably does just that under the hood.
w

waltermcq

05/04/2020, 1:02 AM
thx
4 Views