[Android: LiveData —> Coroutines]. Probably you...
# coroutines
[Android: LiveData —> Coroutines]. Probably you're aware of
from Google's app guide: https://developer.android.com/jetpack/docs/guide#addendum. How do you replicate similar functionality in coroutines world? Can you reuse it? Do you apply some completely different technic? Some thoughts: Case 1: network request, no caching required: Before: return
After: probably just
suspended get(): Result
? Seems enough.
, no need for a stream here. Case 2: network request, return cache first, update cache, return fresh data Before: return
as LiveData (emits two items, cached and refreshed) After? Channels? Actors? (P.S. Does anybody have an example of cache aware Repository with coroutines? )
An actor makes sense in this case.
Not sure that actor is required, just a channel for second case, just a suspend function for the first
@ghedeon since everything can be pararellism and sequential. You can check from cache first and do other stuff. In Rx world you can use concat(cache, remote)
@radityagumay you're not wrong, but I can't see how it's related. You mean how to implement it inside of Repository? Because the question was more like how to pass it up, to presentation layer.
@gildor @Dico did you see some real examples of channels applied this way, by any chance? I'm afraid in the moment I switch to channel - I'll open the Pandora box 😬. The next day there will be the need to combine, map/reduce, subscribe/resubscribe, etc. and it will help me to know that I'm not alone here 🙂. I know all of this is possible, still don't see many people adopting. I've checked Chris Banes tivi app, after his talk at kotlinkonf, and he is mixing coroutines with rx
. Still no channels..
No. I would've brainstormed a solution if I had time today for that. Sorry