Empty combine <Iterable<Flow<T>>> not emitting anything
See original GitHub issueI just debugged an issue where I did not get any events from the flows combine function.
I had a code where I combined the latest values of a List<Observable<Recipe>>
into an Observable<List<Recipe>>
by using combineLatest
.
I refactored that code to use flows’'s combine
to convert a List<Flow<Recipe>>
into a Flow<List<Recipe>>
.
However this never emitted an item if the data sources were empty.
I expect that the function:
@ExperimentalCoroutinesApi
public inline fun <reified T, R> combine(
flows: Iterable<Flow<T>>,
crossinline transform: suspend (Array<T>) -> R
): Flow<R> {
val flowArray = flows.toList().toTypedArray()
return flow {
combineInternal(
flowArray,
arrayFactory = { arrayOfNulls(flowArray.size) },
transform = { emit(transform(it)) })
}
}
gives me an empty array in the transform method but it just hangs forever. (coroutines 1.3.2)
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (9 by maintainers)
Top Results From Across the Web
itertools — Functions creating iterators for efficient looping ...
The combination tuples are emitted in lexicographic ordering according to the order of the input iterable. So, if the input iterable is sorted,...
Read more >Personalizing Templates with Handlebars
Iterable message templates use Handlebars helpers and block helpers to display user and event profile data in a way that is most suitable...
Read more >How to merge two maps into one with keys from the first map ...
How can I create a new map from two maps of maps so that the resulting map only includes matches where keys are...
Read more >Python's map(): Processing Iterables Without a Loop
In this tutorial, you'll learn: How Python's map() works; How to transform different types of Python iterables using map(); How to combine map() ......
Read more >Python TypeError: 'float' object not iterable Solution
The result of the “TypeError: 'float' object not iterable” error is usually trying to use a number to tell a for loop how...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@mtrakal consider this more expressive code:
I do agree that empty flows should not be confused with a flow with a default ‘empty value’. Maybe this should be Room-configurable, but I think Flow behavior here should not change.
Edit: I’m not sure why your Room flow is not emitting an empty list. Room docs suggest that should be the behavior:
https://developer.android.com/reference/androidx/room/Query
It’s wrong to close this issue. I’ve just debugged my code and reached to this unexpected behavior (I was about to report this as a new bug). A “combine” that is passed an empty list of flows should emit once the current result status, which is an empty list. The current behavior will hit many users.