Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why to use new feature Single in RxJava?

Tags:

rx-java

Documentation is pretty clear about what this alternative of Observable doing:

The Single class implements the Reactive Pattern for a single value response. See Observable for the implementation of the Reactive Pattern for a stream or vector of values. Single behaves the same as Observable except that it can only emit either a single successful value or an error (there is no "onComplete" notification as there is for Observable) Like an Observable, a Single is lazy, can be either "hot" or "cold", synchronous or asynchronous.

But I can't see a reason apart that it is might be simpler then Observable sometimes, where and why to use it?

like image 368
ar-g Avatar asked Nov 29 '25 16:11

ar-g


1 Answers

There are cases where it makes sense for an observable to only return a single item and end (or error). This blog post explains it succinctly.

like image 186
JohnWowUs Avatar answered Dec 03 '25 04:12

JohnWowUs