Created
February 26, 2020 22:55
-
-
Save DjangoLC/857aaaf9d7e650a02f117d578fc7398a to your computer and use it in GitHub Desktop.
Snippet code about how to implement coroutines with retrofit and 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
// Method in retrofit Ws | |
suspend fun getDestinyRequestR() : Response<List<ResponseDestinyRequest>> | |
// Method in repository | |
override suspend fun getDestinyRequest(): List<DestinyRequest> { | |
val response = destinyRequestWs.getDestinyRequestR() | |
//Do stuff | |
return response | |
} | |
// Method in viewModel | |
fun getDestinyRequest() { | |
viewModelScope.launch(Dispatchers.IO) { | |
val response = requestMemberRepository.getDestinyRequest() | |
//Do stuff | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment