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