https://kotlinlang.org logo
#coroutines
Title
# coroutines
d

Dias

09/12/2018, 8:16 PM
I used python before, and I converted one of the http servers that I had into async/await app, I used async libraries like aiopg or aiohttp. But say I have jdbi/jdbc based app, how do I convert it into async using coroutines without an async library or spawning any additional threads?
t

thevery

09/12/2018, 8:36 PM
you cannot convert blocking call to async without explicit or implicit threads; simple option is smth like
fun asyncCall() = async(IO) { blockingCall() }
d

Dias

09/12/2018, 10:50 PM
I just wonder how it’s done in python, I don’t think it spawns any threads
say you make 1000 long standing http calls and you await for them, will kotlin spawn up 1000 threads?
I guess you control number of threads with thread executor, but if a coroutine requires a thread to perform that http call, what is the point of coroutine at all?
t

thevery

09/12/2018, 11:54 PM
aiohttp is built as async from scratch, you can check kotlinx-io or ktor as sample of similar approach implementation in kotlin
d

Dias

09/13/2018, 6:06 PM
aiopg though is just an async wrapper around blocking psycopg library, so I was looking for an example of how to do similar thing in kotlin
will have a look at kotlin-x and ktor, thanks
2 Views