https://kotlinlang.org logo
#coroutines
Title
# coroutines
though you probably need slightly other link
g

gildor

09/13/2018, 1:49 AM
how do I convert/wrap those blocking database/http calls into async calls
there is no real way to convert blocking calls to real non-blocking, no such magic. But you always can wrap blocking call to coroutine that runs this blocking call on a separate thread (and blocks it), but for user of this API it looks as async API and doesn’t block thread where it invoked. Simplest way (with new IO disptatcher)
Copy code
suspend fun someDbCall(sql:String) =    withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
      someBlockingDbCall(sql)
 }
6 Views