There are a few specialized flavors of Observable
that are explicitly set up for one or no emissions: Single
, Maybe
, and Completable
. These all follow the Observable
closely and should be intuitive to use in your reactive coding workflow. You can create them in similar ways as the Observable
(for example, they each have their own create()
factory), but certain Observable
operators may return them too.
Single<T>
is essentially an Observable<T>
that will only emit one item. It works just like an Observable, but it is limited only to operators that make sense for a single emission. It has its own SingleObserver
interface as well:
interfaceSingleObserver<T> { voidonSubscribe(Disposabled); voidonSuccess(T value); voidonError(Throwableerror); }
The onSuccess()
essentially consolidates onNext()
and onComplete()
into a single event that accepts the one emission. When you call subscribe()
against a Single, you provide the lambdas...