Hey folks. I'm trying to use `Coroutines Flow` wit...
# android
h
Hey folks. I'm trying to use
Coroutines Flow
with Room and I'm receiving the following error:
g
Could you show the declaration that you use
h
image.png
g
Remove suspend modifier, you don't need it with flow
Room sees suspend modifier and it mark that you just return value from request, not subscribe on value changes. So it tries to return result of this select and convert it to Flow, but you don't have such adapter and you don't need it
h
Thank you. I'm gonna try
@gildor It worked...
I open the implementation of
Flow.collect
and I saw that it is
suspend
marked
g
Essentially your declaration is the same as: Single<Observable<HistoryResult>>
Flow collect for sure suspend
h
so I kinda get it why I don't need to mark the fun as suspend
g
Because you do not collect anything
Room just create Flow for you
that you can collect where you want
h
aaah
I got it
So...
Flow
with Room is useful if I want to show "item by item" on the screen of something like that?
g
No
h
Cause I just could use a list of data normal
g
Flow is the same as LiveData or Observable
h
and observe is
g
When you use flow you getting current result and subscribe on database updates
h
Got it
So when I want to just have entire
list<data>
I use
suspend
fun
returning list<data> and when I want to subscribe a
list<data>
and observe it I use
Flow
?
g
yes
first is one-time operation, second subscribe on changes of requested data until coroutine where you do
collect
is not cancelled
👍 1
h
Cool... Thank you mate
With that, I just realized that I don't need
Flow
now, maybe I was just excited about the Room support. Cause I'm really in love with Coroutines and its apis 😄
👍 1