I have a flow with ids, and I wanna to get flow of...
# squarelibraries
p
I have a flow with ids, and I wanna to get flow of database objects. I’m trying to do it like this:
Copy code
indicesFlow
    .map { indices ->
        database.usersQueries
            .getBy(indices)
            .asFlow()
            .mapToList()
    }
    .flattenConcat()
    .collect { users ->

    }
For some reason map gets called only for the first emitted item, and when I emit new indices to
indexesFlow
it’s not get called anymore and so collect it not get called too. I expect old database flow to be cancelled and be replaced with a new one. And if I replace database flow with a basic flow with emit, same code work fine for new indexesFlow emits
Copy code
indicesFlow
    .map { indices ->
        flow {
            emit("$indices")
        }
    }
    .flattenConcat()
    .collect { strings ->

    }
I’m just starting exploring flows, what am I missing here?
n
sqldelight flows never "end" see: https://kotlinlang.slack.com/archives/C5HT9AL7Q/p1622166059055900 so i am not sure how flattenConcat() handles multiple ongoing flows.. or if that is what you want `you probably want to call
but i think mapToList() might be stalling your code
try
withContext(IO) { query.execute() }
if you want for each id in
indexFlow
to execute the query only once
p
ok, I was wrong when thought that
flattenConcat
will cancel previous flow, there’s
flatMapLatest
for this purpose, and it works as expected. Still not sure why with
flattenConcat
new items are not getting passed: all flows created inside map should continue passing values in this case.
m
just get rid of the map and concat, and just use flatmaplatest directly