https://kotlinlang.org logo
Title
t

tseisel

08/27/2019, 12:08 PM
Both
conflate
and
combine
internally use channels to buffer elements, launching a new coroutine to collect elements from upstream. In your case, neither consumer nor producer are slow so results are quite random (depends on what coroutine resumes first). Try to introduce delays after conflate (for example, in the body of
combine
) and in you'll see that results becomes determinictic.
m

Marko Mitic

08/27/2019, 12:09 PM
not a expert but I can give it a try: 1) race condition as conflated flows are collected on separate coroutine 2) it's unlikely to produce it as elements from flow1 are emitted in short span and collector always gets the most recent value emitted. This also explains
1A/n3A
and
3A
results - if flow1 emits first you'll get
3A
and if flow2 is faster, it will wait for first element to be emitted from flow2, miss second one and get last emitted - 3
t

tseisel

08/27/2019, 12:09 PM
I agree this is quite confusing : I'd expect that without
conflate
, it would always emit
1A 2A 3A
m

Marko Mitic

08/27/2019, 12:13 PM
In 1.3.0RC
combine
was named
combineLatest
which better describes the behavior
j

Jan Skrasek

08/27/2019, 12:47 PM
Thank you for pointing out the channel - combine uses it internally and therefore it doesn't work even without conflate.