gastsail / CocktailApp

Cocktails Android App with Clean Architecture, MVVM , Retrofit, Coroutines, Navigation Components , Room, Dagger Hilt, Cache Strategy and Coroutines Flow
MIT License
446 stars 77 forks source link

Why? And what about failures? #8

Open LouisCAD opened 3 years ago

LouisCAD commented 3 years ago

https://github.com/gastsail/CocktailApp/blob/65f3a9c776cf096a5572c52cc502a38c106b1b1d/app/src/main/java/com/g/tragosapp/data/remote/NetworkDataSource.kt#L18-27

gastsail commented 3 years ago

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

LouisCAD commented 3 years ago

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

LouisCAD commented 3 years ago

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

gastsail commented 3 years ago

The reason of using callbackFlow there is that in this repo https://github.com/gastsail/CocktailApp/blob/5506f6e498dff39fb8c54a58596356e802a71a52/app/src/main/java/com/g/tragosapp/domain/DefaultCocktailRepository.kt#L30 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

gastsail commented 3 years ago

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