Skip to content

Instantly share code, notes, and snippets.

@DjangoLC
Created February 26, 2020 22:55
Show Gist options
  • Save DjangoLC/857aaaf9d7e650a02f117d578fc7398a to your computer and use it in GitHub Desktop.
Save DjangoLC/857aaaf9d7e650a02f117d578fc7398a to your computer and use it in GitHub Desktop.
Snippet code about how to implement coroutines with retrofit and viewmodel
// 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