Jan Skrasek
08/27/2019, 11:48 AM3A or 1A\n3A
2) Why it never produce 2B?
3) Why without conflate() it gives also random results?
4) Why without conflate() it returns sometimes 2B?
Link for playground: https://play.kotlinlang.org/#eyJ2ZXJzaW9uIjoiMS4zLjMxIiwiY29kZSI6ImltcG9ydCBrb3RsaW54LmNvcm91dGluZXMuKlxuaW1wb3J0IGtvdGxpbnguY29yb3V0aW5lcy5jaGFubmVscy4qXG5pbXBvcnQga290bGlueC5jb3JvdXRpbmVzLmZsb3cuKlxuXG5zdXNwZW5kIGZ1biBtYWluKCkge1xuXHR2YWwgZmxvdzE6IEZsb3c8SW50PiA9IGZsb3dPZigxLCAyLCAzKS5jb25mbGF0ZSgpXG4gICAgdmFsIGZsb3cyOiBGbG93PFN0cmluZz4gPSBmbG93T2YoXCJBXCIpLmNvbmZsYXRlKClcbiAgICBcbiAgICBjb21iaW5lKGZsb3cxLCBmbG93MikgeyBhLCBiIC0+IFxuXHRcdGEudG9TdHJpbmcoKSArIGJcbiAgICB9LmNvbGxlY3QgeyBwcmludGxuKGl0KSB9XG59IiwicGxhdGZvcm0iOiJqYXZhIiwiYXJncyI6IiJ9tseisel
08/27/2019, 12:08 PMconflate 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.Marko Mitic
08/27/2019, 12:09 PM1A/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 - 3tseisel
08/27/2019, 12:09 PMconflate, it would always emit 1A 2A 3AMarko Mitic
08/27/2019, 12:13 PMcombine was named combineLatest which better describes the behaviorJan Skrasek
08/27/2019, 12:47 PM