Package rx.observers
Class Subscribers
- java.lang.Object
-
- rx.observers.Subscribers
-
public final class Subscribers extends java.lang.Object
Helper methods and utilities for creating and working withSubscriber
objects.
-
-
Constructor Summary
Constructors Modifier Constructor Description private
Subscribers()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Subscriber<T>
create(Action1<? super T> onNext)
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>
create(Action1<? super T> onNext, Action1<java.lang.Throwable> onError)
Creates anSubscriber
that receives the emissions of anyObservable
it subscribes to viaonNext
and handles anyonError
notification but ignores anonCompleted
notification.static <T> Subscriber<T>
create(Action1<? super T> onNext, Action1<java.lang.Throwable> onError, Action0 onComplete)
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>
from(Observer<? super T> o)
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.
-
-
-
Method Detail
-
empty
public static <T> Subscriber<T> 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
public static <T> Subscriber<T> from(Observer<? super T> o)
Converts anObserver
into aSubscriber
.- Type Parameters:
T
- the observed value type- Parameters:
o
- theObserver
to convert- Returns:
- a
Subscriber
version ofo
-
create
public static <T> Subscriber<T> create(Action1<? super T> onNext)
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:
java.lang.IllegalArgumentException
- ifonNext
isnull
-
create
public static <T> Subscriber<T> create(Action1<? super T> onNext, Action1<java.lang.Throwable> onError)
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:
java.lang.IllegalArgumentException
- if eitheronNext
oronError
arenull
-
create
public static <T> Subscriber<T> create(Action1<? super T> onNext, Action1<java.lang.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:
java.lang.IllegalArgumentException
- if eitheronNext
,onError
, oronComplete
arenull
-
wrap
public 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.- 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
-
-