The Observable.create method
Let's look at the signature of the method first:
public final static <T> Observable<T> create(OnSubscribe<T>)
It takes a parameter of type OnSubscribe
. This interface extends the Action1<Subscriber<? super T>>
interface; in other words, this type has only one method, taking one argument of type Subscriber<T>
and returning nothing. This function will be called every time the Observable.subscribe()
method is invoked. Its argument, an instance of the Subscriber
class, is in fact the observer, subscribing to the Observable
instance (here, the Subscriber
class and Observer interface have the same role). We'll be talking about them later in this chapter). We can invoke the onNext()
, onError()
, and onCompleted()
methods on it, implementing our own custom behavior.
It's easier to comprehend this with an example. Let's implement a simple version of the Observable.from(Iterabale<T>)
method:
<T> Observable...