if JDBC is blocking, what is the benefit of using ...
# ktor
w
if JDBC is blocking, what is the benefit of using coroutines for async database calls through exposed w/ postgres?
d
Multithreaded database calls?
n
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
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
@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
Probably does just that under the hood.
w
thx