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

darych

09/25/2018, 3:10 PM
Hi! I'm newbie in coroutines. I'm wondering how I can make Spring's RestTemplate work with coroutines? I'm going to check ktor's source code. But from my perspective, network intercation in RestTemplate is blocking and there will be no improvement with coroutines. Am I right?
e

enleur

09/25/2018, 3:13 PM
nope, you should run it on IO pool
d

darych

09/25/2018, 3:14 PM
Sorry, didn't get it. Run RestTemplate on IO pool?
e

enleur

09/25/2018, 3:18 PM
yes, you wrap a blocking call with IO context and use it in your coroutines
👍 1
d

darych

09/25/2018, 3:19 PM
Oh, thank you. Will try find some info on this.
e

enleur

09/25/2018, 3:23 PM
Copy code
withContext(<http://Dispatchers.IO|Dispatchers.IO>){
    .. your blocking code
}
👍 1
d

darych

09/25/2018, 3:25 PM
Thank you so much!
k

kenkyee

09/25/2018, 3:28 PM
also look at this: https://github.com/konrad-kaminski/spring-kotlin-coroutine Unless you're using Spring-Fu, Spring doesn't have built-in coroutine support
3 Views