Skip to content

Instantly share code, notes, and snippets.

@Shivamdhuria
Last active Dec 12, 2020
Embed
What would you like to do?
private fun getDogImages(): Flow<ResultWrapper> {
return flow {
emit(ResultWrapper.Loading(true))
delay(3000)
val randomNumber = (0..5).random()
emit(ResultWrapper.Loading(false))
if (randomNumber < 3) {
throw IOException()
}
emit(ResultWrapper.Success(getList()))
}
}
private fun getList(): List<String> {
val list = listOf<String>(
"https://images.dog.ceo/breeds/retriever-curly/n02099429_935.jpg",
....
"https://images.dog.ceo/breeds/pekinese/n02086079_952.jpg"
)
return list
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment