Created
September 10, 2020 01:58
-
-
Save carolinemusyoka/54b785ea72fcbc7124cbbc01d10c0818 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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