Top Description Constructors Methods
io.reactivex.flowables

public abstract Class ConnectableFlowable<T>

extends Flowable<T>
Class Inheritance
Known Direct Subclasses
io.reactivex.internal.operators.flowable.FlowableReplay, io.reactivex.internal.operators.flowable.FlowableReplay.ConnectableFlowableReplay, io.reactivex.internal.operators.flowable.FlowablePublish, io.reactivex.internal.operators.flowable.FlowablePublishAlt
Type Parameters
<T>
the type of items emitted by the ConnectableFlowable
Imports
java.util.concurrent.TimeUnit, org.reactivestreams.Subscriber, io.reactivex.*, io.reactivex.annotations.*, io.reactivex.disposables.Disposable, io.reactivex.functions.Consumer, io.reactivex.internal.functions.*, io.reactivex.internal.operators.flowable.*, io.reactivex.internal.util.ConnectConsumer, io.reactivex.plugins.RxJavaPlugins, io.reactivex.schedulers.Schedulers

A ConnectableFlowable resembles an ordinary Flowable, 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 Flowable#subscribe to the Flowable before the Flowable begins emitting items.

See Also
RxJava Wiki: Connectable Observable Operators

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Flowable<T>

Returns:

a Flowable that automatically connects to this ConnectableFlowable when the first Subscriber subscribes
autoConnect
()

Returns a Flowable that automatically connects (at most once) to this ConnectableFlowable when the first Subscriber subscribes.

public Flowable<T>

Returns:

a Flowable that automatically connects to this ConnectableFlowable when the specified number of Subscribers subscribe to it
autoConnect
(int
the number of subscribers to await before calling connect on the ConnectableFlowable. A non-positive value indicates an immediate connection.
numberOfSubscribers
)

Returns a Flowable that automatically connects (at most once) to this ConnectableFlowable when the specified number of Subscribers subscribe to it.

public Flowable<T>

Returns:

a Flowable that automatically connects to this ConnectableFlowable when the specified number of Subscribers subscribe to it and calls the specified callback with the Subscription associated with the established connection
autoConnect
(int
the number of subscribers to await before calling connect on the ConnectableFlowable. A non-positive value indicates an immediate connection.
numberOfSubscribers
,
Consumer<? super Disposable>
the callback Consumer that will receive the Subscription representing the established connection
connection
)

Returns a Flowable that automatically connects (at most once) to this ConnectableFlowable when the specified number of Subscribers subscribe to it and calls the specified callback with the Subscription associated with the established connection.

public abstract void
connect(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 ConnectableFlowable to begin emitting the items from its underlying Flowable to its Subscribers.

public final Disposable

Returns:

the subscription representing the connection
connect
()

Instructs the ConnectableFlowable to begin emitting the items from its underlying Flowable to its Subscribers.

private ConnectableFlowable<T>

Returns:

the ConnectableFlowable to work with
onRefCount
()

Apply a workaround for a race condition with the regular publish().refCount() so that racing subscribers and refCount won't hang.

public Flowable<T>

Returns:

a Flowable
refCount
()

Returns a Flowable that stays connected to this ConnectableFlowable as long as there is at least one subscription to this ConnectableFlowable.

public final Flowable<T>

Returns:

the new Flowable instance
refCount
(int
the number of subscribers required to connect to the upstream
subscriberCount
)

Connects to the upstream ConnectableFlowable if the number of subscribed subscriber reaches the specified count and disconnect if all subscribers have unsubscribed.

public final Flowable<T>

Returns:

the new Flowable instance
refCount
(long
the time to wait before disconnecting after all subscribers unsubscribed
timeout
,
TimeUnit
the time unit of the timeout
unit
)

Connects to the upstream ConnectableFlowable if the number of subscribed subscriber reaches 1 and disconnect after the specified timeout if all subscribers have unsubscribed.

public final Flowable<T>

Returns:

the new Flowable instance
refCount
(long
the time to wait before disconnecting after all subscribers unsubscribed
timeout
,
TimeUnit
the time unit of the timeout
unit
,
Scheduler
the target scheduler to wait on before disconnecting
scheduler
)

Connects to the upstream ConnectableFlowable if the number of subscribed subscriber reaches 1 and disconnect after the specified timeout if all subscribers have unsubscribed.

public final Flowable<T>

Returns:

the new Flowable instance
refCount
(int
the number of subscribers required to connect to the upstream
subscriberCount
,
long
the time to wait before disconnecting after all subscribers unsubscribed
timeout
,
TimeUnit
the time unit of the timeout
unit
)

Connects to the upstream ConnectableFlowable if the number of subscribed subscriber reaches the specified count and disconnect after the specified timeout if all subscribers have unsubscribed.

public final Flowable<T>

Returns:

the new Flowable instance
refCount
(int
the number of subscribers required to connect to the upstream
subscriberCount
,
long
the time to wait before disconnecting after all subscribers unsubscribed
timeout
,
TimeUnit
the time unit of the timeout
unit
,
Scheduler
the target scheduler to wait on before disconnecting
scheduler
)

Connects to the upstream ConnectableFlowable if the number of subscribed subscriber reaches the specified count and disconnect after the specified timeout if all subscribers have unsubscribed.

Inherited from io.reactivex.Flowable:
allambambArrayambWithanyasblockingFirstblockingFirstblockingForEachblockingIterableblockingIterableblockingLastblockingLastblockingLatestblockingMostRecentblockingNextblockingSingleblockingSingleblockingSubscribeblockingSubscribeblockingSubscribeblockingSubscribeblockingSubscribeblockingSubscribeblockingSubscribeblockingSubscribebufferbufferbufferbufferbufferbufferbufferbufferbufferbufferbufferbufferbufferbufferbufferbufferbufferbufferbufferbufferSizecachecacheWithInitialCapacitycastcollectcollectIntocombineLatestcombineLatestcombineLatestcombineLatestcombineLatestcombineLatestcombineLatestcombineLatestcombineLatestcombineLatestcombineLatestcombineLatestcombineLatestcombineLatestDelayErrorcombineLatestDelayErrorcombineLatestDelayErrorcombineLatestDelayErrorcombineLatestDelayErrorcombineLatestDelayErrorcomposeconcatconcatconcatconcatconcatconcatconcatArrayconcatArrayDelayErrorconcatArrayEagerconcatArrayEagerconcatArrayEagerDelayErrorconcatArrayEagerDelayErrorconcatDelayErrorconcatDelayErrorconcatDelayErrorconcatEagerconcatEagerconcatEagerconcatEagerconcatMapconcatMapconcatMapCompletableconcatMapCompletableconcatMapCompletableDelayErrorconcatMapCompletableDelayErrorconcatMapCompletableDelayErrorconcatMapDelayErrorconcatMapDelayErrorconcatMapEagerconcatMapEagerconcatMapEagerDelayErrorconcatMapEagerDelayErrorconcatMapIterableconcatMapIterableconcatMapMaybeconcatMapMaybeconcatMapMaybeDelayErrorconcatMapMaybeDelayErrorconcatMapMaybeDelayErrorconcatMapSingleconcatMapSingleconcatMapSingleDelayErrorconcatMapSingleDelayErrorconcatMapSingleDelayErrorconcatWithconcatWithconcatWithconcatWithcontainscountcreatedebouncedebouncedebouncedefaultIfEmptydeferdelaydelaydelaydelaydelaydelaydelaySubscriptiondelaySubscriptiondelaySubscriptiondematerializedematerializedistinctdistinctdistinctdistinctUntilChangeddistinctUntilChangeddistinctUntilChangeddoAfterNextdoAfterTerminatedoFinallydoOnCanceldoOnCompletedoOnEachdoOnEachdoOnErrordoOnLifecycledoOnNextdoOnRequestdoOnSubscribedoOnTerminateelementAtelementAtelementAtOrErroremptyerrorerrorfilterfirstfirstElementfirstOrErrorflatMapflatMapflatMapflatMapflatMapflatMapflatMapflatMapflatMapflatMapflatMapflatMapflatMapCompletableflatMapCompletableflatMapIterableflatMapIterableflatMapIterableflatMapIterableflatMapMaybeflatMapMaybeflatMapSingleflatMapSingleforEachforEachWhileforEachWhileforEachWhilefromArrayfromCallablefromFuturefromFuturefromFuturefromFuturefromIterablefromPublishergenerategenerategenerategenerategenerategroupBygroupBygroupBygroupBygroupBygroupBygroupJoinhideignoreElementsintervalintervalintervalintervalintervalRangeintervalRangeisEmptyjoinjustjustjustjustjustjustjustjustjustjustlastlastElementlastOrErrorliftlimitmapmaterializemergemergemergemergemergemergemergemergemergeArraymergeArraymergeArrayDelayErrormergeArrayDelayErrormergeDelayErrormergeDelayErrormergeDelayErrormergeDelayErrormergeDelayErrormergeDelayErrormergeDelayErrormergeDelayErrormergeWithmergeWithmergeWithmergeWithneverobserveOnobserveOnobserveOnofTypeonBackpressureBufferonBackpressureBufferonBackpressureBufferonBackpressureBufferonBackpressureBufferonBackpressureBufferonBackpressureBufferonBackpressureBufferonBackpressureDroponBackpressureDroponBackpressureLatestonErrorResumeNextonErrorResumeNextonErrorReturnonErrorReturnItemonExceptionResumeNextonTerminateDetachparallelparallelparallelpublishpublishpublishpublishrangerangeLongrebatchRequestsreducereducereduceWithrepeatrepeatrepeatUntilrepeatWhenreplayreplayreplayreplayreplayreplayreplayreplayreplayreplayreplayreplayreplayreplayreplayreplayretryretryretryretryretryretryUntilretryWhensafeSubscribesamplesamplesamplesamplesamplesamplescanscanscanWithsequenceEqualsequenceEqualsequenceEqualsequenceEqualserializesharesinglesingleElementsingleOrErrorskipskipskipskipLastskipLastskipLastskipLastskipLastskipLastskipUntilskipWhilesortedsortedstartWithstartWithstartWithstartWithArraysubscribesubscribesubscribesubscribesubscribesubscribesubscribesubscribeActualsubscribeOnsubscribeOnsubscribeWithswitchIfEmptyswitchMapswitchMapswitchMapCompletableswitchMapCompletableDelayErrorswitchMapDelayErrorswitchMapDelayErrorswitchMapMaybeswitchMapMaybeDelayErrorswitchMapSingleswitchMapSingleDelayErrorswitchOnNextswitchOnNextswitchOnNextDelayErrorswitchOnNextDelayErrortaketaketaketakeLasttakeLasttakeLasttakeLasttakeLasttakeLasttakeLasttakeLasttakeLasttakeUntiltakeUntiltakeWhiletesttesttestthrottleFirstthrottleFirstthrottleLastthrottleLastthrottleLatestthrottleLatestthrottleLatestthrottleLatestthrottleWithTimeoutthrottleWithTimeouttimeIntervaltimeIntervaltimeIntervaltimeIntervaltimeouttimeouttimeouttimeouttimeouttimeouttimeouttimeouttimertimertimestamptimestamptimestamptimestamptotoFuturetoListtoListtoListtoMaptoMaptoMaptoMultimaptoMultimaptoMultimaptoMultimaptoObservabletoSortedListtoSortedListtoSortedListtoSortedListunsafeCreateunsubscribeOnusingusingwindowwindowwindowwindowwindowwindowwindowwindowwindowwindowwindowwindowwindowwindowwindowwindowwindowwindowwindowwithLatestFromwithLatestFromwithLatestFromwithLatestFromwithLatestFromwithLatestFromzipzipzipzipzipzipzipzipzipzipzipzipzipArrayzipIterablezipWithzipWithzipWithzipWith

Constructor Detail

ConnectableFlowableback to summary
public ConnectableFlowable()

Method Detail

autoConnectback to summary
public Flowable<T> autoConnect()

Returns a Flowable that automatically connects (at most once) to this ConnectableFlowable when the first Subscriber subscribes.

The connection happens after the first subscription and happens at most once during the lifetime of the returned Flowable. If this ConnectableFlowable terminates, the connection is never renewed, no matter how Subscribers come and go. Use refCount() to renew a connection or dispose an active connection when all Subscribers have cancelled their Subscriptions.

This overload does not allow disconnecting the connection established via connect(Consumer). Use the autoConnect(int, Consumer) overload to gain access to the Disposable representing the only connection.

Returns:Flowable<T>

a Flowable that automatically connects to this ConnectableFlowable when the first Subscriber subscribes

Annotations
@NonNull
See Also
refCount(), autoConnect(int, Consumer)
autoConnectback to summary
public Flowable<T> autoConnect(int numberOfSubscribers)

Returns a Flowable that automatically connects (at most once) to this ConnectableFlowable when the specified number of Subscribers subscribe to it.

The connection happens after the given number of subscriptions and happens at most once during the lifetime of the returned Flowable. If this ConnectableFlowable terminates, the connection is never renewed, no matter how Subscribers come and go. Use refCount() to renew a connection or dispose an active connection when all Subscribers have cancelled their Subscriptions.

This overload does not allow disconnecting the connection established via connect(Consumer). Use the autoConnect(int, Consumer) overload to gain access to the Disposable representing the only connection.

Parameters
numberOfSubscribers:int

the number of subscribers to await before calling connect on the ConnectableFlowable. A non-positive value indicates an immediate connection.

Returns:Flowable<T>

a Flowable that automatically connects to this ConnectableFlowable when the specified number of Subscribers subscribe to it

Annotations
@NonNull
autoConnectback to summary
public Flowable<T> autoConnect(int numberOfSubscribers, Consumer<? super Disposable> connection)

Returns a Flowable that automatically connects (at most once) to this ConnectableFlowable when the specified number of Subscribers subscribe to it and calls the specified callback with the Subscription associated with the established connection.

The connection happens after the given number of subscriptions and happens at most once during the lifetime of the returned Flowable. If this ConnectableFlowable terminates, the connection is never renewed, no matter how Subscribers come and go. Use refCount() to renew a connection or dispose an active connection when all Subscribers have cancelled their Subscriptions.

Parameters
numberOfSubscribers:int

the number of subscribers to await before calling connect on the ConnectableFlowable. A non-positive value indicates an immediate connection.

connection:Consumer<? super Disposable>

the callback Consumer that will receive the Subscription representing the established connection

Returns:Flowable<T>

a Flowable that automatically connects to this ConnectableFlowable when the specified number of Subscribers subscribe to it and calls the specified callback with the Subscription associated with the established connection

Annotations
@NonNull
connectback to summary
public abstract void connect(Consumer<? super Disposable> connection)

Instructs the ConnectableFlowable to begin emitting the items from its underlying Flowable to its Subscribers.

Parameters
connection: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

See Also
ReactiveX documentation: Connect
connectback to summary
public final Disposable connect()

Instructs the ConnectableFlowable to begin emitting the items from its underlying Flowable to its Subscribers.

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

Returns:Disposable

the subscription representing the connection

See Also
ReactiveX documentation: Connect
onRefCountback to summary
private ConnectableFlowable<T> onRefCount()

Apply a workaround for a race condition with the regular publish().refCount() so that racing subscribers and refCount won't hang.

Returns:ConnectableFlowable<T>

the ConnectableFlowable to work with

Since
2.2.10
refCountback to summary
public Flowable<T> refCount()

Returns a Flowable that stays connected to this ConnectableFlowable as long as there is at least one subscription to this ConnectableFlowable.

Backpressure:
The operator itself doesn't interfere with backpressure which is determined by the upstream ConnectableFlowable's backpressure behavior.
Scheduler:
This refCount overload does not operate on any particular Scheduler.
Returns:Flowable<T>

a Flowable

Annotations
@NonNull
@CheckReturnValue
@SchedulerSupport:none
@BackpressureSupport:PASS_THROUGH
See Also
ReactiveX documentation: RefCount, refCount(int), refCount(long, TimeUnit), refCount(int, long, TimeUnit)
refCountback to summary
public final Flowable<T> refCount(int subscriberCount)

Connects to the upstream ConnectableFlowable if the number of subscribed subscriber reaches the specified count and disconnect if all subscribers have unsubscribed.

Backpressure:
The operator itself doesn't interfere with backpressure which is determined by the upstream ConnectableFlowable's backpressure behavior.
Scheduler:
This refCount overload does not operate on any particular Scheduler.

History: 2.1.14 - experimental

Parameters
subscriberCount:int

the number of subscribers required to connect to the upstream

Returns:Flowable<T>

the new Flowable instance

Annotations
@CheckReturnValue
@SchedulerSupport:none
@BackpressureSupport:PASS_THROUGH
Since
2.2
refCountback to summary
public final Flowable<T> refCount(long timeout, TimeUnit unit)

Connects to the upstream ConnectableFlowable if the number of subscribed subscriber reaches 1 and disconnect after the specified timeout if all subscribers have unsubscribed.

Backpressure:
The operator itself doesn't interfere with backpressure which is determined by the upstream ConnectableFlowable's backpressure behavior.
Scheduler:
This refCount overload operates on the computation Scheduler.

History: 2.1.14 - experimental

Parameters
timeout:long

the time to wait before disconnecting after all subscribers unsubscribed

unit:TimeUnit

the time unit of the timeout

Returns:Flowable<T>

the new Flowable instance

Annotations
@CheckReturnValue
@SchedulerSupport:io.reactivex:computation
@BackpressureSupport:PASS_THROUGH
Since
2.2
See Also
refCount(long, TimeUnit, Scheduler)
refCountback to summary
public final Flowable<T> refCount(long timeout, TimeUnit unit, Scheduler scheduler)

Connects to the upstream ConnectableFlowable if the number of subscribed subscriber reaches 1 and disconnect after the specified timeout if all subscribers have unsubscribed.

Backpressure:
The operator itself doesn't interfere with backpressure which is determined by the upstream ConnectableFlowable's backpressure behavior.
Scheduler:
This refCount overload operates on the specified Scheduler.

History: 2.1.14 - experimental

Parameters
timeout:long

the time to wait before disconnecting after all subscribers unsubscribed

unit:TimeUnit

the time unit of the timeout

scheduler:Scheduler

the target scheduler to wait on before disconnecting

Returns:Flowable<T>

the new Flowable instance

Annotations
@CheckReturnValue
@SchedulerSupport:custom
@BackpressureSupport:PASS_THROUGH
Since
2.2
refCountback to summary
public final Flowable<T> refCount(int subscriberCount, long timeout, TimeUnit unit)

Connects to the upstream ConnectableFlowable if the number of subscribed subscriber reaches the specified count and disconnect after the specified timeout if all subscribers have unsubscribed.

Backpressure:
The operator itself doesn't interfere with backpressure which is determined by the upstream ConnectableFlowable's backpressure behavior.
Scheduler:
This refCount overload operates on the computation Scheduler.

History: 2.1.14 - experimental

Parameters
subscriberCount:int

the number of subscribers required to connect to the upstream

timeout:long

the time to wait before disconnecting after all subscribers unsubscribed

unit:TimeUnit

the time unit of the timeout

Returns:Flowable<T>

the new Flowable instance

Annotations
@CheckReturnValue
@SchedulerSupport:io.reactivex:computation
@BackpressureSupport:PASS_THROUGH
Since
2.2
See Also
refCount(int, long, TimeUnit, Scheduler)
refCountback to summary
public final Flowable<T> refCount(int subscriberCount, long timeout, TimeUnit unit, Scheduler scheduler)

Connects to the upstream ConnectableFlowable if the number of subscribed subscriber reaches the specified count and disconnect after the specified timeout if all subscribers have unsubscribed.

Backpressure:
The operator itself doesn't interfere with backpressure which is determined by the upstream ConnectableFlowable's backpressure behavior.
Scheduler:
This refCount overload operates on the specified Scheduler.

History: 2.1.14 - experimental

Parameters
subscriberCount:int

the number of subscribers required to connect to the upstream

timeout:long

the time to wait before disconnecting after all subscribers unsubscribed

unit:TimeUnit

the time unit of the timeout

scheduler:Scheduler

the target scheduler to wait on before disconnecting

Returns:Flowable<T>

the new Flowable instance

Annotations
@CheckReturnValue
@SchedulerSupport:custom
@BackpressureSupport:PASS_THROUGH
Since
2.2