codelab-kotlin-coroutines icon indicating copy to clipboard operation
codelab-kotlin-coroutines copied to clipboard

refreshTitle withContext giving errors from code suplied from "Use Kotlin Coroutines in your Android App" 8th slide

Open DerSIlent opened this issue 5 years ago • 0 comments

`suspend fun refreshTitle() { // interact with blocking network and IO calls from a coroutine withContext(Dispatchers.IO) { val result = try { // Make network request using a blocking call network.fetchNextTitle().execute() } catch (cause: Throwable) { // If the network throws an exception, inform the caller throw TitleRefreshError("Unable to refresh title", cause) }

   if (result.isSuccessful) {
       // Save it to database
       titleDao.insertTitle(Title(result.body()!!))
   } else {
       // If it's not successful, inform the callback of the error
       throw TitleRefreshError("Unable to refresh title", null)
   }

} }`

does not actually work when pasting it in sourc code

DerSIlent avatar Jul 12 '20 20:07 DerSIlent