Skip to content

Unexpected difference between flatmap and concatmap when the stream has only one element #4206

Closed
@rrevol

Description

@rrevol

Hello,

I am encountering an unexpected behavior in a piece of code I wrote. I've tried to narrow down a reproduction case in this gist.

To sum up :

  • It's on RxJava 1.1.7
  • I have 2 Observables built in such that I am sure their elements match
  • These observables come from a flatmap on another observable that emits only one element
  • I zip the 2 observables and see that in the output some elements do not match
  • important : I use observeOn/subscribeOn because in real life, my process performs io.

What I observe :

  • if I replace flatmap by concatmap, no more problem. The way I understand both operations, they should not be different if the mapped stream emits only one element. Do I miss sth ?
  • If I remove the observeOn/subscribeOn, no more problem, so I suspect a concurrency issue
  • The way it looks is that flatmap shuffles data, but I did a simpler test (use method initTestFlowWithOrderCheck instead of initTestFlowWithZip ) that seems to discard this hypothesis
  • In the end, it could be a concurrency issue in zip but I've read the operator extensively and could not see any problem with it.

Here I am with my investigation, I may have missed something obvious to someone else so I'm looking forward to have your feedback on that.

Thx

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions