Coroutines101
Coroutines101 copied to clipboard
Intro to Coroutines on Android using MVVM
Kotlin Coroutines on Android
Some examples of how Coroutines can be used on Android in an app built using MVVM architecture.
The examples that illustrate error handling randomly throw an Exception that gets caught and displayed by a Snackbar
.
Branches
- RxJava: Load Github repos using Retrofit
-
Coroutines using
CoroutineScope
: Load Github repos usingCoroutineScope
and Retrofit -
Coroutines using
viewModelScope
: Load Github repos usingviewModelScope
and Retrofit - Coroutines making sync calls: Load two images over the network synchronously
-
Coroutines using
async
/await
: Load two images over the network asynchronously -
Coroutines using
CoroutineExceptionHandler
: Load two images over the network synchronously and handle exceptions using customCoroutineExceptionHandler
-
Coroutines using
try
/catch
: Load two images synchronously over the network and handle exceptions usingtry
/catch
-
Coroutines using
async
andtry
/catch
: Load two images asynchronously over the network and handle exceptions usingtry
/catch
if any of the images fail to load. First image to fail will cancel its parent job which will cancel the rest of its children (in this case, the other image loading).
Contributions
If you have any comments or would like to contribute additional examples, feel free to open an issue or submit a pull request.