Aleksey Chugaev
12/22/2019, 9:47 AM...
mainScope.launch {
val dataFromServer = ktorClient.callFirstApi() // runs on main thread - success
sqlDelightClient.storeData(dataFromServer) // runs on background using withContext(workerDispatcher) - success
val otherDataFromServer = ktorClient.callSecondApi() // runs on main thread - fails with JsonDecodingException: Invalid JSON at 0: Expected '{, kind: CLASS'
}
I log request details and if I replay the request in Postman I get valid response.
If I don't use withContext(workerDispatcher)
to store data to database everything works fine and second API is successful.
Note: I run API on the main thread because Ktor doesn't support background threads yet (should be added in 1.3.0).kpgalligan
12/22/2019, 2:38 PMAleksey Chugaev
12/22/2019, 8:20 PM./gradlew dependencies
only shows one version of coroutines being used - 1.3.2-native-mt-SNAPSHOTKris Wong
12/23/2019, 2:36 PMwithContext
for the second call, but is it blocking the main thread? otherwise the 3rd call will happen before the second completes.Kris Wong
12/23/2019, 2:36 PMrunBlocking
Aleksey Chugaev
12/23/2019, 8:39 PMmainScope.launch {...}
Aleksey Chugaev
12/23/2019, 8:40 PM