Created
September 18, 2019 01:59
-
-
Save ininmm/75fddeb1b8086fc35334bf230248ac21 to your computer and use it in GitHub Desktop.
使用 Coroutines 的 ViewModel
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
suspend fun getToken(): Token { ...... } | |
suspend fun verify(token, userName: String): Boolean { ...... } | |
suspend fun requestAndSaveUserData(userName: String): Result { ...... } | |
fun login(userName: String) { | |
GlobalScope.launch { | |
try { | |
val token = getToken() | |
val isLogin = verify(token, userName) | |
if (isLogin) { | |
val success = requestAndSaveUserData(userName) | |
if (success) { | |
showLoginSuccess("Success") | |
} | |
} | |
...... | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment