gastsail / CocktailApp

Cocktails Android App with Clean Architecture, MVVM , Retrofit, Coroutines, Navigation Components , Room, Dagger Hilt, Cache Strategy and Coroutines Flow

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why? And what about failures?

LouisCAD opened this issue · comments

Since is a suspend function, inside Resource.success you are callind the API which is another suspend function, any exceptions thrown by that call in the Resource.Success will propagate the error to the catch block in the viewmodel

But why use callbackFlow, and why make it a Flow at all?

And why wrap into Resource.Success if you don't wrap it in unsuccessful cases?

The reason of using callbackFlow there is that in this repo

override suspend fun getCocktailByName(cocktailName: String): Flow<Resource<List<Cocktail>>> =
I don't want to return Livedata to emit cache data before the concrete call to the server which brings up the latest data.

About the failure, is beign handled in the viewmodel when that success operation returns an exception, it will be propagated to the viewmodel catch block of the calling function

Any improvements in the code will be more than welcome @LouisCAD 💯