Skip to content

Instantly share code, notes, and snippets.

@carolinemusyoka
Created September 10, 2020 01:58
Show Gist options
  • Save carolinemusyoka/54b785ea72fcbc7124cbbc01d10c0818 to your computer and use it in GitHub Desktop.
Save carolinemusyoka/54b785ea72fcbc7124cbbc01d10c0818 to your computer and use it in GitHub Desktop.
class MainViewModel(private val mainRepository: MainRepository) : ViewModel() {
fun getSuperHeroes() = liveData(Dispatchers.IO) {
emit(Resource.loading(data = null))
try {
emit(Resource.success(data = mainRepository.getSuperHeroes()))
} catch (exception: Exception) {
emit(Resource.error(data = null, message = exception.message ?: "Error Occurred!"))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment