Class ConnectableObservable<T>

java.lang.Object
rx.Observable<T>
rx.observables.ConnectableObservable<T>
Type Parameters:
T - the type of items emitted by the ConnectableObservable
Direct Known Subclasses:
OperatorMulticast, OperatorPublish, OperatorReplay

public abstract class ConnectableObservable<T> extends Observable<T>
A ConnectableObservable resembles an ordinary Observable, except that it does not begin emitting items when it is subscribed to, but only when its connect() method is called. In this way you can wait for all intended Subscribers to Observable.subscribe() to the Observable before the Observable begins emitting items.

See Also:
  • Constructor Details

  • Method Details

    • connect

      public final Subscription connect()
      Instructs the ConnectableObservable to begin emitting the items from its underlying Observable to its Subscribers.

      To disconnect from a synchronous source, use the connect(rx.functions.Action1) method.

      Returns:
      the subscription representing the connection
      See Also:
    • connect

      public abstract void connect(Action1<? super Subscription> connection)
      Instructs the ConnectableObservable to begin emitting the items from its underlying Observable to its Subscribers.
      Parameters:
      connection - the action that receives the connection subscription before the subscription to source happens allowing the caller to synchronously disconnect a synchronous source
      See Also:
    • refCount

      public Observable<T> refCount()
      Returns an Observable that stays connected to this ConnectableObservable as long as there is at least one subscription to this ConnectableObservable.
      Returns:
      a Observable
      See Also:
    • autoConnect

      @Beta public Observable<T> autoConnect()
      Returns an Observable that automatically connects to this ConnectableObservable when the first Subscriber subscribes.
      Returns:
      an Observable that automatically connects to this ConnectableObservable when the first Subscriber subscribes
      Since:
      (if this graduates from Experimental/Beta to supported, replace this parenthetical with the release number)
    • autoConnect

      @Beta public Observable<T> autoConnect(int numberOfSubscribers)
      Returns an Observable that automatically connects to this ConnectableObservable when the specified number of Subscribers subscribe to it.
      Parameters:
      numberOfSubscribers - the number of subscribers to await before calling connect on the ConnectableObservable. A non-positive value indicates an immediate connection.
      Returns:
      an Observable that automatically connects to this ConnectableObservable when the specified number of Subscribers subscribe to it
      Since:
      (if this graduates from Experimental/Beta to supported, replace this parenthetical with the release number)
    • autoConnect

      @Beta public Observable<T> autoConnect(int numberOfSubscribers, Action1<? super Subscription> connection)
      Returns an Observable that automatically connects to this ConnectableObservable when the specified number of Subscribers subscribe to it and calls the specified callback with the Subscription associated with the established connection.
      Parameters:
      numberOfSubscribers - the number of subscribers to await before calling connect on the ConnectableObservable. A non-positive value indicates an immediate connection.
      connection - the callback Action1 that will receive the Subscription representing the established connection
      Returns:
      an Observable that automatically connects to this ConnectableObservable when the specified number of Subscribers subscribe to it and calls the specified callback with the Subscription associated with the established connection
      Since:
      (if this graduates from Experimental/Beta to supported, replace this parenthetical with the release number)