Package rx.observers

Class Observers


  • public final class Observers
    extends java.lang.Object
    Helper methods and utilities for creating and working with Observer objects.
    • Field Detail

      • EMPTY

        private static final Observer<java.lang.Object> EMPTY
    • Constructor Detail

      • Observers

        private Observers()
    • Method Detail

      • empty

        public static <T> Observer<T> empty()
        Returns an inert Observer that does nothing in response to the emissions or notifications from any Observable it subscribes to but will throw an exception if its onError method is called.
        Type Parameters:
        T - the observed value type
        Returns:
        an inert Observer
      • create

        public static <T> Observer<T> create​(Action1<? super T> onNext)
        Creates an Observer 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:
        an Observer that calls onNext for each emitted item from the Observable the Observer subscribes to
        Throws:
        java.lang.IllegalArgumentException - if onNext is null
      • create

        public static <T> Observer<T> create​(Action1<? super T> onNext,
                                             Action1<java.lang.Throwable> onError)
        Creates an Observer 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 Observer that calls onNext for each emitted item from the Observable the Observer subscribes to, and calls onError if the Observable notifies of an error
        Throws:
        java.lang.IllegalArgumentException - if either onNext or onError are null
      • create

        public static <T> Observer<T> create​(Action1<? super T> onNext,
                                             Action1<java.lang.Throwable> onError,
                                             Action0 onComplete)
        Creates an Observer 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 Observer that calls onNext for each emitted item from the Observable the Observer 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:
        java.lang.IllegalArgumentException - if either onNext, onError, or onComplete are null