Single vs Observable in Java RX

Xitrum picture Xitrum · Mar 30, 2016 · Viewed 9.5k times · Source

In the new release, reactiveX introduced Single, as a variant of Observable http://reactivex.io/documentation/single.html

Which is nice to have since in my current use-case, I have multiple executions, and each of them only returns a single result. So it will make sense if I change from using Observable to Single.

But then as a part of my use-case, for those multiple execution above, I need to concat them into one Observable stream later on (to get results from all above executions).

So now my question is, what is more beneficial in term of performance?

  1. Using Observable for each execution, although I know that the execution will return only 1 result.

or

  1. Using the Single for each execution, and only convert them to Observable when I need to concat the streams later on?

Thank you.

Answer

Leo Droidcoder picture Leo Droidcoder · May 23, 2017

Single is meant to be used when you expect a single value response.
Observable on the other hand is to be used for a stream or vector values.
So in terms of Reactive Pattern it's enough to use Single in case you expect the only 1 result and don't want to manipulate data