Class PublishSubject<T>

  • Type Parameters:
    T - the type of items observed and emitted by the Subject
    All Implemented Interfaces:
    Observer<T>


    public final class PublishSubject<T>
    extends Subject<T,T>
    Subject that, once an Observer has subscribed, emits all subsequently observed items to the subscriber.

    Example usage:

      PublishSubject<Object> subject = PublishSubject.create(); // observer1 will receive all onNext and onCompleted events subject.subscribe(observer1); subject.onNext("one"); subject.onNext("two"); // observer2 will only receive "three" and onCompleted subject.subscribe(observer2); subject.onNext("three"); subject.onCompleted();  
    • Constructor Detail

      • PublishSubject

        protected PublishSubject(Observable.OnSubscribe<T> onSubscribe,
                                 rx.subjects.SubjectSubscriptionManager<T> state)
    • Method Detail

      • create

        public static <T> PublishSubject<T> create()
        Creates and returns a new PublishSubject.
        Type Parameters:
        T - the value type
        Returns:
        the new PublishSubject
      • hasObservers

        public boolean hasObservers()
        Description copied from class: Subject
        Indicates whether the Subject has Observers subscribed to it.
        Specified by:
        hasObservers in class  Subject<T,T>
        Returns:
        true if there is at least one Observer subscribed to this Subject, false otherwise
      • hasThrowable

        @Beta
        public boolean hasThrowable()
        Check if the Subject has terminated with an exception.
        Returns:
        true if the subject has received a throwable through onError.
      • hasCompleted

        @Beta
        public boolean hasCompleted()
        Check if the Subject has terminated normally.
        Returns:
        true if the subject completed normally via onCompleted
      • getThrowable

        @Beta
        public Throwable getThrowable()
        Returns the Throwable that terminated the Subject.
        Returns:
        the Throwable that terminated the Subject or null if the subject hasn't terminated yet or it terminated normally.