Package rx.observers
Class Subscribers
java.lang.Object
rx.observers.Subscribers
Helper methods and utilities for creating and working with
Subscriber
objects.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Subscriber
<T> Creates aSubscriber
that receives the emissions of anyObservable
it subscribes to viaonNext
but ignoresonCompleted
notifications; it will throw anOnErrorNotImplementedException
ifonError
is invoked.static <T> Subscriber
<T> Creates anSubscriber
that receives the emissions of anyObservable
it subscribes to viaonNext
and handles anyonError
notification but ignores anonCompleted
notification.static <T> Subscriber
<T> Creates anSubscriber
that receives the emissions of anyObservable
it subscribes to viaonNext
and handles anyonError
oronCompleted
notifications.static <T> Subscriber
<T> empty()
Returns an inertSubscriber
that does nothing in response to the emissions or notifications from anyObservable
it subscribes to.static <T> Subscriber
<T> Converts anObserver
into aSubscriber
.static <T> Subscriber
<T> wrap
(Subscriber<? super T> subscriber) Returns a newSubscriber
that passes all events tosubscriber
, has backpressure controlled bysubscriber
and uses the subscription list ofsubscriber
whenSubscriber.add(rx.Subscription)
is called.
-
Constructor Details
-
Subscribers
private Subscribers()
-
-
Method Details
-
empty
Returns an inertSubscriber
that does nothing in response to the emissions or notifications from anyObservable
it subscribes to. Will throw anOnErrorNotImplementedException
ifonError
method is called- Type Parameters:
T
- the observed value type- Returns:
- an inert
Observer
-
from
Converts anObserver
into aSubscriber
.- Type Parameters:
T
- the observed value type- Parameters:
o
- theObserver
to convert- Returns:
- a
Subscriber
version ofo
-
create
Creates aSubscriber
that receives the emissions of anyObservable
it subscribes to viaonNext
but ignoresonCompleted
notifications; it will throw anOnErrorNotImplementedException
ifonError
is invoked.- Type Parameters:
T
- the observed value type- Parameters:
onNext
- a function that handles each item emitted by anObservable
- Returns:
- a
Subscriber
that callsonNext
for each emitted item from theObservable
theSubscriber
subscribes to - Throws:
IllegalArgumentException
- ifonNext
isnull
-
create
Creates anSubscriber
that receives the emissions of anyObservable
it subscribes to viaonNext
and handles anyonError
notification but ignores anonCompleted
notification.- Type Parameters:
T
- the observed value type- Parameters:
onNext
- a function that handles each item emitted by anObservable
onError
- a function that handles an error notification if one is sent by anObservable
- Returns:
- an
Subscriber
that callsonNext
for each emitted item from theObservable
theSubscriber
subscribes to, and callsonError
if theObservable
notifies of an error - Throws:
IllegalArgumentException
- if eitheronNext
oronError
arenull
-
create
public static <T> Subscriber<T> create(Action1<? super T> onNext, Action1<Throwable> onError, Action0 onComplete) Creates anSubscriber
that receives the emissions of anyObservable
it subscribes to viaonNext
and handles anyonError
oronCompleted
notifications.- Type Parameters:
T
- the observed value type- Parameters:
onNext
- a function that handles each item emitted by anObservable
onError
- a function that handles an error notification if one is sent by anObservable
onComplete
- a function that handles a sequence complete notification if one is sent by anObservable
- Returns:
- an
Subscriber
that callsonNext
for each emitted item from theObservable
theSubscriber
subscribes to, callsonError
if theObservable
notifies of an error, and callsonComplete
if theObservable
notifies that the observable sequence is complete - Throws:
IllegalArgumentException
- if eitheronNext
,onError
, oronComplete
arenull
-
wrap
Returns a newSubscriber
that passes all events tosubscriber
, has backpressure controlled bysubscriber
and uses the subscription list ofsubscriber
whenSubscriber.add(rx.Subscription)
is called.- Type Parameters:
T
- the observed value type- Parameters:
subscriber
- the Subscriber to wrap.- Returns:
- a new Subscriber that passes all events to
subscriber
, has backpressure controlled bysubscriber
and usessubscriber
to manage unsubscription. - Since:
- 1.1.0
-