ConnectableObservable
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 Observable#subscribe to the Observable
before the Observable begins emitting items.
When the upstream terminates, the ConnectableObservable remains in this terminated state and,
depending on the actual underlying implementation, relays cached events to late Observers.
In order to reuse and restart this ConnectableObservable, the reset() method has to be called.
When called, this ConnectableObservable will appear as fresh, unconnected source to new Observers.
Disposing the connection will reset the ConnectableObservable to its fresh state and there is no need to call
reset() in this case.
Note that although connect() and reset() are safe to call from multiple threads, it is recommended
a dedicated thread or business logic manages the connection or resetting of a ConnectableObservable so that
there is no unwanted signal loss due to early connect() or reset() calls while Observers are
still being subscribed to to this ConnectableObservable to receive signals from the get go.
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public @NonNull Observable | Returns: a newObservable instance that automatically connects to this ConnectableObservable
when the first Observer subscribesReturns an |
| public @NonNull Observable | Returns: a newObservable instance that automatically connects to this ConnectableObservable
when the specified number of Observers subscribe to itthe number of subscribers to await before calling connect
on the numberOfObservers)ConnectableObservable. A non-positive value indicates
an immediate connection.Returns an |
| public @NonNull Observable | Returns: a newObservable instance that automatically connects to this ConnectableObservable
when the specified number of Observers subscribe to it and calls the
specified callback with the Disposable associated with the established connectionthe number of subscribers to await before calling connect
on the numberOfObservers, @NonNull Consumer<? super Disposable> ConnectableObservable. A non-positive value indicates
an immediate connection.the callback connection)Consumer that will receive the Disposable representing the
established connectionReturns an |
| public abstract void | connect(@NonNull Consumer<? super Disposable>
the action that receives the connection subscription before the subscription to source happens
allowing the caller to synchronously disconnect a synchronous source connection)Instructs the |
| public final @NonNull Disposable | Returns: theDisposable representing the connectionInstructs the |
| public @NonNull Observable | Returns: a newObservable instanceReturns an |
| public final @NonNull Observable | Returns: the newObservable instancethe number of observerCount)Observers required to connect to the upstreamConnects to the upstream |
| public final @NonNull Observable | Returns: the newObservable instancethe time to wait before disconnecting after all timeout, @NonNull TimeUnit Observers unsubscribedthe time unit of the timeout unit)Connects to the upstream |
| public final @NonNull Observable | Returns: the newObservable instancethe time to wait before disconnecting after all timeout, @NonNull TimeUnit Observers unsubscribedthe time unit of the timeout unit, @NonNull Scheduler the target scheduler to wait on before disconnecting scheduler)Connects to the upstream |
| public final @NonNull Observable | Returns: the newObservable instancethe number of observerCount, long Observers required to connect to the upstreamthe time to wait before disconnecting after all timeout, @NonNull TimeUnit Observers unsubscribedthe time unit of the timeout unit)Connects to the upstream |
| public final @NonNull Observable | Returns: the newObservable instancethe number of observerCount, long Observers required to connect to the upstreamthe time to wait before disconnecting after all timeout, @NonNull TimeUnit Observers unsubscribedthe time unit of the timeout unit, @NonNull Scheduler the target scheduler to wait on before disconnecting scheduler)Connects to the upstream |
| public abstract void | reset()
Resets this |
| ConnectableObservable | back to summary |
|---|---|
| public ConnectableObservable() | |
| autoConnect | back to summary |
|---|---|
| public @NonNull Observable Returns an
The connection happens after the first subscription and happens at most once
during the lifetime of the returned
This overload does not allow disconnecting the connection established via
| |
| autoConnect | back to summary |
|---|---|
| public @NonNull Observable Returns an
The connection happens after the given number of subscriptions and happens at most once
during the lifetime of the returned
This overload does not allow disconnecting the connection established via
| |
| autoConnect | back to summary |
|---|---|
| public @NonNull Observable Returns an
The connection happens after the given number of subscriptions and happens at most once
during the lifetime of the returned
| |
| connect | back to summary |
|---|---|
| public abstract void connect(@NonNull Consumer<? super Disposable> connection) Instructs the
| |
| connect | back to summary |
|---|---|
| public final @NonNull Disposable connect() Instructs the
To disconnect from a synchronous source, use the
| |
| refCount | back to summary |
|---|---|
| public @NonNull Observable Returns an
| |
| refCount | back to summary |
|---|---|
| public final @NonNull Observable Connects to the upstream
History: 2.1.14 - experimental
| |
| refCount | back to summary |
|---|---|
| public final @NonNull Observable Connects to the upstream
History: 2.1.14 - experimental
| |
| refCount | back to summary |
|---|---|
| public final @NonNull Observable Connects to the upstream
History: 2.1.14 - experimental
| |
| refCount | back to summary |
|---|---|
| public final @NonNull Observable Connects to the upstream
History: 2.1.14 - experimental
| |
| refCount | back to summary |
|---|---|
| public final @NonNull Observable Connects to the upstream
History: 2.1.14 - experimental
| |
| reset | back to summary |
|---|---|
| public abstract void reset() Resets this
Calling this method on a fresh or active
| |