Philip Dukhov
05/29/2021, 7:21 PMindicesFlow
.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
indicesFlow
.map { indices ->
flow {
emit("$indices")
}
}
.flattenConcat()
.collect { strings ->
}
I’m just starting exploring flows, what am I missing here?Nikky
05/29/2021, 10:42 PMNikky
05/29/2021, 10:43 PMNikky
05/29/2021, 10:44 PMwithContext(IO) { query.execute() }
if you want for each id in indexFlow
to execute the query only oncePhilip Dukhov
05/30/2021, 11:25 AMflattenConcat
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.myanmarking
06/02/2021, 1:42 PM