public abstract class

ConnectableObservable

extends Observable<T>
java.lang.Object
   ↳ io.reactivex.Observable<T>
     ↳ io.reactivex.observables.ConnectableObservable<T>

Class Overview

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 Observers to subscribe() to the Observable before the Observable begins emitting items.

Summary

Public Constructors
ConnectableObservable()
Public Methods
Observable<T> autoConnect(int numberOfSubscribers, Consumer<? super Disposable> 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.
Observable<T> autoConnect()
Returns an Observable that automatically connects to this ConnectableObservable when the first Observer subscribes.
Observable<T> autoConnect(int numberOfSubscribers)
Returns an Observable that automatically connects to this ConnectableObservable when the specified number of Observers subscribe to it.
final Disposable connect()
Instructs the ConnectableObservable to begin emitting the items from its underlying Observable to its Observers.
abstract void connect(Consumer<? super Disposable> connection)
Instructs the ConnectableObservable to begin emitting the items from its underlying Observable to its Observers.
Observable<T> refCount()
Returns an Observable that stays connected to this ConnectableObservable as long as there is at least one subscription to this ConnectableObservable.
[Expand]
Inherited Methods
From class io.reactivex.Observable
From class java.lang.Object
From interface io.reactivex.ObservableSource

Public Constructors

public ConnectableObservable ()

Public Methods

public Observable<T> autoConnect (int numberOfSubscribers, Consumer<? super Disposable> 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 Consumer 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

public Observable<T> autoConnect ()

Returns an Observable that automatically connects to this ConnectableObservable when the first Observer subscribes.

Returns
  • an Observable that automatically connects to this ConnectableObservable when the first Observer subscribes

public Observable<T> autoConnect (int numberOfSubscribers)

Returns an Observable that automatically connects to this ConnectableObservable when the specified number of Observers 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

public final Disposable connect ()

Instructs the ConnectableObservable to begin emitting the items from its underlying Observable to its Observers.

To disconnect from a synchronous source, use the connect(Consumer) method.

Returns
  • the subscription representing the connection

public abstract void connect (Consumer<? super Disposable> connection)

Instructs the ConnectableObservable to begin emitting the items from its underlying Observable to its Observers.

Parameters
connection the action that receives the connection subscription before the subscription to source happens allowing the caller to synchronously disconnect a synchronous source

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