1) Why does this code produce random results? Eith...
# coroutines
t
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
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
I agree this is quite confusing : I'd expect that without
conflate
, it would always emit
1A 2A 3A
m
In 1.3.0RC
combine
was named
combineLatest
which better describes the behavior
j
Thank you for pointing out the channel - combine uses it internally and therefore it doesn't work even without conflate.