CocktailApp icon indicating copy to clipboard operation
CocktailApp copied to clipboard

Why? And what about failures?

Open LouisCAD opened this issue 4 years ago • 5 comments

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

LouisCAD avatar Mar 16 '21 19:03 LouisCAD

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

gastsail avatar Mar 16 '21 20:03 gastsail

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

LouisCAD avatar Mar 17 '21 11:03 LouisCAD

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

LouisCAD avatar Mar 17 '21 11:03 LouisCAD

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 avatar Mar 17 '21 11:03 gastsail

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

gastsail avatar Mar 17 '21 11:03 gastsail