Package rx.observers

Class Subscribers

java.lang.Object
rx.observers.Subscribers

public final class Subscribers extends Object
Helper methods and utilities for creating and working with Subscriber objects.
  • Constructor Details

    • Subscribers

      private Subscribers()
  • Method Details

    • empty

      public static <T> Subscriber<T> empty()
      Returns an inert Subscriber that does nothing in response to the emissions or notifications from any Observable it subscribes to. Will throw an OnErrorNotImplementedException if onError 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 an Observer into a Subscriber.
      Type Parameters:
      T - the observed value type
      Parameters:
      o - the Observer to convert
      Returns:
      a Subscriber version of o
    • create

      public static <T> Subscriber<T> create(Action1<? super T> onNext)
      Creates a Subscriber that receives the emissions of any Observable it subscribes to via onNext but ignores onCompleted notifications; it will throw an OnErrorNotImplementedException if onError is invoked.
      Type Parameters:
      T - the observed value type
      Parameters:
      onNext - a function that handles each item emitted by an Observable
      Returns:
      a Subscriber that calls onNext for each emitted item from the Observable the Subscriber subscribes to
      Throws:
      IllegalArgumentException - if onNext is null
    • create

      public static <T> Subscriber<T> create(Action1<? super T> onNext, Action1<Throwable> onError)
      Creates an Subscriber that receives the emissions of any Observable it subscribes to via onNext and handles any onError notification but ignores an onCompleted notification.
      Type Parameters:
      T - the observed value type
      Parameters:
      onNext - a function that handles each item emitted by an Observable
      onError - a function that handles an error notification if one is sent by an Observable
      Returns:
      an Subscriber that calls onNext for each emitted item from the Observable the Subscriber subscribes to, and calls onError if the Observable notifies of an error
      Throws:
      IllegalArgumentException - if either onNext or onError are null
    • create

      public static <T> Subscriber<T> create(Action1<? super T> onNext, Action1<Throwable> onError, Action0 onComplete)
      Creates an Subscriber that receives the emissions of any Observable it subscribes to via onNext and handles any onError or onCompleted notifications.
      Type Parameters:
      T - the observed value type
      Parameters:
      onNext - a function that handles each item emitted by an Observable
      onError - a function that handles an error notification if one is sent by an Observable
      onComplete - a function that handles a sequence complete notification if one is sent by an Observable
      Returns:
      an Subscriber that calls onNext for each emitted item from the Observable the Subscriber subscribes to, calls onError if the Observable notifies of an error, and calls onComplete if the Observable notifies that the observable sequence is complete
      Throws:
      IllegalArgumentException - if either onNext, onError, or onComplete are null
    • wrap

      public static <T> Subscriber<T> wrap(Subscriber<? super T> subscriber)
      Returns a new Subscriber that passes all events to subscriber, has backpressure controlled by subscriber and uses the subscription list of subscriber when Subscriber.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 by subscriber and uses subscriber to manage unsubscription.
      Since:
      1.1.0