Zoltan Demant
10/11/2023, 6:57 AMprivate val version = MutableStateFlow(0L).also { state ->
scope.launch {
registry.repositories.map { repository ->
repository.changes
}.merge().collect {
state.update { version ->
version.inc()
}
}
}
}
Sam
10/11/2023, 7:59 AMStateFlow
? A bit more info would help, but it looks like this is just:
val version = registry.repositories
.flatMapConcat { it.changes }
.runningFold(0L) { acc, _ -> acc + 1 }
Zoltan Demant
10/11/2023, 8:15 AMrepository.change
is a Flow<...>
and while I can use combine(flows)
that will only emit after each flow has emitted a value I believe?Sam
10/11/2023, 9:09 AMflatMapConcat
(or the now-deprecated merge
) it will collect all the changes from the first repository before moving on to the next repository. If you want to collect changes from multiple repositories at the same time, you could use flatMapMerge
instead.Zoltan Demant
10/11/2023, 11:48 AMregistry.repositories.map { it.changes }.merge().scan(0L) { version, _ ->
version + 1
}
👍🏽 Thanks for the help, this clearly shows me that despite how much I work with and read about coroutines, I still have so much more to learn!