https://kotlinlang.org logo
#android
Title
# android
h

henrikhorbovyi

09/01/2019, 5:07 PM
Hey folks. I'm trying to use
Coroutines Flow
with Room and I'm receiving the following error:
g

gildor

09/02/2019, 2:22 AM
Could you show the declaration that you use
h

henrikhorbovyi

09/03/2019, 12:34 AM
image.png
g

gildor

09/03/2019, 1:01 AM
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

henrikhorbovyi

09/03/2019, 1:10 AM
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

gildor

09/03/2019, 1:22 AM
Essentially your declaration is the same as: Single<Observable<HistoryResult>>
Flow collect for sure suspend
h

henrikhorbovyi

09/03/2019, 1:23 AM
so I kinda get it why I don't need to mark the fun as suspend
g

gildor

09/03/2019, 1:23 AM
Because you do not collect anything
Room just create Flow for you
that you can collect where you want
h

henrikhorbovyi

09/03/2019, 1:23 AM
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

gildor

09/03/2019, 1:25 AM
No
h

henrikhorbovyi

09/03/2019, 1:25 AM
Cause I just could use a list of data normal
g

gildor

09/03/2019, 1:25 AM
Flow is the same as LiveData or Observable
h

henrikhorbovyi

09/03/2019, 1:25 AM
and observe is
g

gildor

09/03/2019, 1:25 AM
When you use flow you getting current result and subscribe on database updates
h

henrikhorbovyi

09/03/2019, 1:27 AM
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

gildor

09/03/2019, 1:28 AM
yes
first is one-time operation, second subscribe on changes of requested data until coroutine where you do
collect
is not cancelled
👍 1
h

henrikhorbovyi

09/03/2019, 1:34 AM
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