Package rx.observers
Class Subscribers
- java.lang.Object
-
- rx.observers.Subscribers
-
public final class Subscribers extends java.lang.ObjectHelper methods and utilities for creating and working withSubscriberobjects.
-
-
Constructor Summary
Constructors Modifier Constructor Description privateSubscribers()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Subscriber<T>create(Action1<? super T> onNext)Creates aSubscriberthat receives the emissions of anyObservableit subscribes to viaonNextbut ignoresonCompletednotifications; it will throw anOnErrorNotImplementedExceptionifonErroris invoked.static <T> Subscriber<T>create(Action1<? super T> onNext, Action1<java.lang.Throwable> onError)Creates anSubscriberthat receives the emissions of anyObservableit subscribes to viaonNextand handles anyonErrornotification but ignores anonCompletednotification.static <T> Subscriber<T>create(Action1<? super T> onNext, Action1<java.lang.Throwable> onError, Action0 onComplete)Creates anSubscriberthat receives the emissions of anyObservableit subscribes to viaonNextand handles anyonErrororonCompletednotifications.static <T> Subscriber<T>empty()Returns an inertSubscriberthat does nothing in response to the emissions or notifications from anyObservableit subscribes to.static <T> Subscriber<T>from(Observer<? super T> o)Converts anObserverinto aSubscriber.static <T> Subscriber<T>wrap(Subscriber<? super T> subscriber)Returns a newSubscriberthat passes all events tosubscriber, has backpressure controlled bysubscriberand uses the subscription list ofsubscriberwhenSubscriber.add(rx.Subscription)is called.
-
-
-
Method Detail
-
empty
public static <T> Subscriber<T> empty()
Returns an inertSubscriberthat does nothing in response to the emissions or notifications from anyObservableit subscribes to. Will throw anOnErrorNotImplementedExceptionifonErrormethod 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 anObserverinto aSubscriber.- Type Parameters:
T- the observed value type- Parameters:
o- theObserverto convert- Returns:
- a
Subscriberversion ofo
-
create
public static <T> Subscriber<T> create(Action1<? super T> onNext)
Creates aSubscriberthat receives the emissions of anyObservableit subscribes to viaonNextbut ignoresonCompletednotifications; it will throw anOnErrorNotImplementedExceptionifonErroris invoked.- Type Parameters:
T- the observed value type- Parameters:
onNext- a function that handles each item emitted by anObservable- Returns:
- a
Subscriberthat callsonNextfor each emitted item from theObservabletheSubscribersubscribes to - Throws:
java.lang.IllegalArgumentException- ifonNextisnull
-
create
public static <T> Subscriber<T> create(Action1<? super T> onNext, Action1<java.lang.Throwable> onError)
Creates anSubscriberthat receives the emissions of anyObservableit subscribes to viaonNextand handles anyonErrornotification but ignores anonCompletednotification.- Type Parameters:
T- the observed value type- Parameters:
onNext- a function that handles each item emitted by anObservableonError- a function that handles an error notification if one is sent by anObservable- Returns:
- an
Subscriberthat callsonNextfor each emitted item from theObservabletheSubscribersubscribes to, and callsonErrorif theObservablenotifies of an error - Throws:
java.lang.IllegalArgumentException- if eitheronNextoronErrorarenull
-
create
public static <T> Subscriber<T> create(Action1<? super T> onNext, Action1<java.lang.Throwable> onError, Action0 onComplete)
Creates anSubscriberthat receives the emissions of anyObservableit subscribes to viaonNextand handles anyonErrororonCompletednotifications.- Type Parameters:
T- the observed value type- Parameters:
onNext- a function that handles each item emitted by anObservableonError- a function that handles an error notification if one is sent by anObservableonComplete- a function that handles a sequence complete notification if one is sent by anObservable- Returns:
- an
Subscriberthat callsonNextfor each emitted item from theObservabletheSubscribersubscribes to, callsonErrorif theObservablenotifies of an error, and callsonCompleteif theObservablenotifies that the observable sequence is complete - Throws:
java.lang.IllegalArgumentException- if eitheronNext,onError, oronCompletearenull
-
wrap
public static <T> Subscriber<T> wrap(Subscriber<? super T> subscriber)
Returns a newSubscriberthat passes all events tosubscriber, has backpressure controlled bysubscriberand uses the subscription list ofsubscriberwhenSubscriber.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 bysubscriberand usessubscriberto manage unsubscription. - Since:
- 1.1.0
-
-