arekolek
12/08/2022, 3:36 PMfun main() = runBlocking {
val service = createFooService()
val response = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
service.foo()
}
println(response)
}
interface FooService {
@POST("foo")
suspend fun foo(): FooResponse
}
dependencies {
implementation("com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.8.0")
implementation("com.squareup.okhttp3:okhttp:4.10.0")
implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1")
}
streetsofboston
12/08/2022, 3:38 PMsuspend fun main()
?streetsofboston
12/08/2022, 3:38 PMsuspend fun foo()
since it is already suspending, not blocking.arekolek
12/08/2022, 3:40 PMsuspend fun main() = runBlocking {
val response = service.foo()
println(response)
}
it's still the same thing
I run it using ./gradlew run
if that changes anythingRiccardo Lippolis
12/08/2022, 3:41 PMRiccardo Lippolis
12/08/2022, 3:42 PMstreetsofboston
12/08/2022, 3:43 PMRiccardo Lippolis
12/08/2022, 3:43 PMarekolek
12/08/2022, 3:46 PMsuspend fun main() {
val client = okHttpClient()
val service = createFooService(client)
val response = service.foo()
println(response)
client.dispatcher.executorService.shutdown()
client.connectionPool.evictAll()
}
and it seems to work like expected! thanks for the help