Skip to content

Commit f555daa

Browse files
Update README.md
1 parent bfb8d4d commit f555daa

File tree

4 files changed

+57
-25
lines changed

4 files changed

+57
-25
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,15 @@ Sign up to my [newsletter](https://www.lukaslechner.com/newsletter/) to never mi
3737

3838
This project is the foundation of a comprehensive Online Course about [Mastering Kotlin Coroutines for Android Development](https://www.lukaslechner.com/coroutines-on-android/)
3939

40-
![CourseCoroutinesOnAndroid](documentation/images/course.png)
40+
[![CourseCoroutinesOnAndroid](documentation/images/course.png)](https://www.lukaslechner.com/coroutines-on-android/)
41+
42+
## 📢 Sharing is Caring
43+
44+
If you like this project, please tell other developers about it! ❤️
45+
46+
[![Share on Twitter](documentation/images/Twitter_bird_logo.png)](https://twitter.com/intent/tweet?url=https%3A%2F%2Fgithub.com%2FLukasLechnerDev%2FKotlin-Coroutine-Use-Cases-on-Android&text=This%20awesome%20example%20project%20shows%20how%20to%20implement%20the%20most%20common%20use%20cases%20for%20using%20Kotlin%20Coroutines%20for%20Android%20Development%21%20By%20@LukasLechnerDev&hashtags=%23AndroidDev%20%23Kotlin%20%23Coroutines)
47+
48+
If you like, you can follow me on Twitter [**@LukasLechnerDev**](https://twitter.com/LukasLechnerDev).
4149

4250
## ⭐️ Use Cases
4351
1. [Perform single network request](#1-perform-single-network-request)

app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/usecases/coroutines/usecase13/ExceptionHandlingViewModel.kt

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ package com.lukaslechner.coroutineusecasesonandroid.usecases.coroutines.usecase1
33
import androidx.lifecycle.viewModelScope
44
import com.lukaslechner.coroutineusecasesonandroid.base.BaseViewModel
55
import com.lukaslechner.coroutineusecasesonandroid.mock.MockApi
6-
import kotlinx.coroutines.*
6+
import kotlinx.coroutines.CancellationException
7+
import kotlinx.coroutines.CoroutineExceptionHandler
8+
import kotlinx.coroutines.async
9+
import kotlinx.coroutines.launch
710
import timber.log.Timber
811

912
class ExceptionHandlingViewModel(
@@ -37,33 +40,34 @@ class ExceptionHandlingViewModel(
3740
uiState.value = UiState.Loading
3841
viewModelScope.launch {
3942

40-
supervisorScope {
41-
val oreoFeaturesDeferred = async { api.getAndroidVersionFeatures(27) }
42-
val pieFeaturesDeferred = async { api.getAndroidVersionFeatures(28) }
43-
val android10FeaturesDeferred = async { api.getAndroidVersionFeatures(29) }
4443

45-
val versionFeatures = listOf(
46-
oreoFeaturesDeferred,
47-
pieFeaturesDeferred,
48-
android10FeaturesDeferred
49-
).mapNotNull {
50-
try {
51-
it.await()
52-
} catch (exception: Exception) {
53-
// We have to re-throw cancellation exceptions so that
54-
// our Coroutine gets cancelled immediately.
55-
// Otherwise, the CancellationException is ignored
56-
// and the Coroutine keeps running until it reaches the next
57-
// suspension point.
58-
if (exception is CancellationException) {
59-
throw exception
60-
}
61-
Timber.e("Error loading feature data!")
62-
null
44+
//supervisorScope {
45+
val oreoFeaturesDeferred = async { api.getAndroidVersionFeatures(27) }
46+
val pieFeaturesDeferred = async { api.getAndroidVersionFeatures(28) }
47+
val android10FeaturesDeferred = async { api.getAndroidVersionFeatures(29) }
48+
49+
val versionFeatures = listOf(
50+
oreoFeaturesDeferred,
51+
pieFeaturesDeferred,
52+
android10FeaturesDeferred
53+
).mapNotNull {
54+
try {
55+
it.await()
56+
} catch (exception: Exception) {
57+
// We have to re-throw cancellation exceptions so that
58+
// our Coroutine gets cancelled immediately.
59+
// Otherwise, the CancellationException is ignored
60+
// and the Coroutine keeps running until it reaches the next
61+
// suspension point.
62+
if (exception is CancellationException) {
63+
throw exception
6364
}
65+
Timber.e("Error loading feature data!")
66+
null
6467
}
65-
uiState.value = UiState.Success(versionFeatures)
6668
}
69+
uiState.value = UiState.Success(versionFeatures)
70+
//}
6771
}
6872
}
6973
}
1.41 KB
Loading
Lines changed: 20 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)