Skip to content

Instantly share code, notes, and snippets.

@Hasiy
Created March 17, 2020 01:43
Show Gist options
  • Save Hasiy/a4742ce9cfc1a82a76510eb3c617920c to your computer and use it in GitHub Desktop.
Save Hasiy/a4742ce9cfc1a82a76510eb3c617920c to your computer and use it in GitHub Desktop.
BaseViewModel
open class BaseViewModel : ViewModel() {
fun launch(block: suspend () -> Unit, error: suspend (Throwable) -> Unit) =
viewModelScope.launch {
try {
block()
} catch (e: Throwable) {
error(e)
}
}
fun launch(block: suspend () -> Unit) =
viewModelScope.launch {
try {
block()
} catch (e: Throwable) {
LogUtil.e("$e")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment