Hello. I want to use `async` coroutine builder to ...
# coroutines
i
Hello. I want to use
async
coroutine builder to execute some blocking code in parallel. I use my custom thread pool for that. But is it ok to call regular (non-suspending) function inside
async
?
Copy code
fun doSomething(s: String): String {
// blocking code
}

val def1 = async(myContext) { doSomething("a") }
val def2 = async(myContext) { doSomething("b") }
// ...

println("${def1.await()} ${def2.await()}")
r
I think you should use the new
IO
dispatcher for the non-suspending blocking code.
👍 2
i
Thank you. I will try it.
u
@rocketraman are your 'regular' functions blocking or computing? If they are cumputationally intensive the default limit of up to 64 threads might be a little high.
r
I assumed they were blocking as that was what the OP stated. Agreed, if they are computing, there would be no benefit to using the
IO
pool.
u
sorry, wrong mention. I meant @IRomanov