Created
March 17, 2020 01:43
-
-
Save Hasiy/a4742ce9cfc1a82a76510eb3c617920c to your computer and use it in GitHub Desktop.
BaseViewModel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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