T
- the type of items emitted by the ConnectableFlowable
public abstract class ConnectableFlowable<T> extends Flowable<T>
ConnectableFlowable
resembles an ordinary Flowable
, except that it does not begin
emitting items when it is subscribed to, but only when its connect(io.reactivex.rxjava3.functions.Consumer<? super io.reactivex.rxjava3.disposables.Disposable>)
method is called. In this way you
can wait for all intended Subscriber
s to Flowable.subscribe()
to the Flowable
before the Flowable
begins emitting items.
When the upstream terminates, the ConnectableFlowable
remains in this terminated state and,
depending on the actual underlying implementation, relays cached events to late Subscriber
s.
In order to reuse and restart this ConnectableFlowable
, the reset()
method has to be called.
When called, this ConnectableFlowable
will appear as fresh, unconnected source to new Subscriber
s.
Disposing the connection will reset the ConnectableFlowable
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 ConnectableFlowable
so that
there is no unwanted signal loss due to early connect()
or reset()
calls while Subscriber
s are
still being subscribed to to this ConnectableFlowable
to receive signals from the get go.
Constructor and Description |
---|
ConnectableFlowable() |
Modifier and Type | Method and Description |
---|---|
@NonNull Flowable<T> |
autoConnect()
Returns a
Flowable that automatically connects (at most once) to this ConnectableFlowable
when the first Subscriber subscribes. |
@NonNull Flowable<T> |
autoConnect(int numberOfSubscribers)
Returns a
Flowable that automatically connects (at most once) to this ConnectableFlowable
when the specified number of Subscriber s subscribe to it. |
@NonNull Flowable<T> |
autoConnect(int numberOfSubscribers,
@NonNull Consumer<? super Disposable> connection)
Returns a
Flowable that automatically connects (at most once) to this ConnectableFlowable
when the specified number of Subscriber s subscribe to it and calls the
specified callback with the Disposable associated with the established connection. |
@NonNull Disposable |
connect()
Instructs the
ConnectableFlowable to begin emitting the items from its underlying
Flowable to its Subscriber s. |
abstract void |
connect(@NonNull Consumer<? super Disposable> connection)
Instructs the
ConnectableFlowable to begin emitting the items from its underlying
Flowable to its Subscriber s. |
@NonNull Flowable<T> |
refCount()
Returns a
Flowable that stays connected to this ConnectableFlowable as long as there
is at least one subscription to this ConnectableFlowable . |
@NonNull 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. |
@NonNull Flowable<T> |
refCount(int subscriberCount,
long timeout,
@NonNull 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. |
@NonNull Flowable<T> |
refCount(int subscriberCount,
long timeout,
@NonNull TimeUnit unit,
@NonNull 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. |
@NonNull Flowable<T> |
refCount(long timeout,
@NonNull 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. |
@NonNull Flowable<T> |
refCount(long timeout,
@NonNull TimeUnit unit,
@NonNull 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. |
abstract void |
reset()
Resets this
ConnectableFlowable into its fresh state if it has terminated. |
all, amb, ambArray, ambWith, any, blockingFirst, blockingFirst, blockingForEach, blockingForEach, blockingIterable, blockingIterable, blockingLast, blockingLast, blockingLatest, blockingMostRecent, blockingNext, blockingSingle, blockingSingle, blockingStream, blockingStream, blockingSubscribe, blockingSubscribe, blockingSubscribe, blockingSubscribe, blockingSubscribe, blockingSubscribe, blockingSubscribe, blockingSubscribe, buffer, buffer, buffer, buffer, buffer, buffer, buffer, buffer, buffer, buffer, buffer, buffer, buffer, buffer, buffer, buffer, buffer, bufferSize, cache, cacheWithInitialCapacity, cast, collect, collect, collectInto, combineLatest, combineLatest, combineLatest, combineLatest, combineLatest, combineLatest, combineLatest, combineLatest, combineLatest, combineLatest, combineLatestArray, combineLatestArray, combineLatestArrayDelayError, combineLatestArrayDelayError, combineLatestDelayError, combineLatestDelayError, compose, concat, concat, concat, concat, concat, concat, concatArray, concatArrayDelayError, concatArrayEager, concatArrayEager, concatArrayEagerDelayError, concatArrayEagerDelayError, concatDelayError, concatDelayError, concatDelayError, concatEager, concatEager, concatEager, concatEager, concatEagerDelayError, concatEagerDelayError, concatEagerDelayError, concatEagerDelayError, concatMap, concatMap, concatMap, concatMapCompletable, concatMapCompletable, concatMapCompletableDelayError, concatMapCompletableDelayError, concatMapCompletableDelayError, concatMapDelayError, concatMapDelayError, concatMapDelayError, concatMapEager, concatMapEager, concatMapEagerDelayError, concatMapEagerDelayError, concatMapIterable, concatMapIterable, concatMapMaybe, concatMapMaybe, concatMapMaybeDelayError, concatMapMaybeDelayError, concatMapMaybeDelayError, concatMapSingle, concatMapSingle, concatMapSingleDelayError, concatMapSingleDelayError, concatMapSingleDelayError, concatMapStream, concatMapStream, concatWith, concatWith, concatWith, concatWith, contains, count, create, debounce, debounce, debounce, debounce, defaultIfEmpty, defer, delay, delay, delay, delay, delay, delay, delaySubscription, delaySubscription, delaySubscription, dematerialize, distinct, distinct, distinct, distinctUntilChanged, distinctUntilChanged, distinctUntilChanged, doAfterNext, doAfterTerminate, doFinally, doOnCancel, doOnComplete, doOnEach, doOnEach, doOnError, doOnLifecycle, doOnNext, doOnRequest, doOnSubscribe, doOnTerminate, elementAt, elementAt, elementAtOrError, empty, error, error, filter, first, firstElement, firstOrError, firstOrErrorStage, firstStage, flatMap, flatMap, flatMap, flatMap, flatMap, flatMap, flatMap, flatMap, flatMap, flatMap, flatMap, flatMap, flatMapCompletable, flatMapCompletable, flatMapIterable, flatMapIterable, flatMapIterable, flatMapIterable, flatMapMaybe, flatMapMaybe, flatMapSingle, flatMapSingle, flatMapStream, flatMapStream, forEach, forEachWhile, forEachWhile, forEachWhile, fromAction, fromArray, fromCallable, fromCompletable, fromCompletionStage, fromFuture, fromFuture, fromIterable, fromMaybe, fromObservable, fromOptional, fromPublisher, fromRunnable, fromSingle, fromStream, fromSupplier, generate, generate, generate, generate, generate, groupBy, groupBy, groupBy, groupBy, groupBy, groupBy, groupJoin, hide, ignoreElements, interval, interval, interval, interval, intervalRange, intervalRange, isEmpty, join, just, just, just, just, just, just, just, just, just, just, last, lastElement, lastOrError, lastOrErrorStage, lastStage, lift, map, mapOptional, materialize, merge, merge, merge, merge, merge, merge, merge, merge, mergeArray, mergeArray, mergeArrayDelayError, mergeArrayDelayError, mergeDelayError, mergeDelayError, mergeDelayError, mergeDelayError, mergeDelayError, mergeDelayError, mergeDelayError, mergeDelayError, mergeWith, mergeWith, mergeWith, mergeWith, never, observeOn, observeOn, observeOn, ofType, onBackpressureBuffer, onBackpressureBuffer, onBackpressureBuffer, onBackpressureBuffer, onBackpressureBuffer, onBackpressureBuffer, onBackpressureBuffer, onBackpressureBuffer, onBackpressureBuffer, onBackpressureBuffer, onBackpressureDrop, onBackpressureDrop, onBackpressureLatest, onBackpressureLatest, onBackpressureReduce, onBackpressureReduce, onErrorComplete, onErrorComplete, onErrorResumeNext, onErrorResumeWith, onErrorReturn, onErrorReturnItem, onTerminateDetach, parallel, parallel, parallel, publish, publish, publish, publish, range, rangeLong, rebatchRequests, reduce, reduce, reduceWith, repeat, repeat, repeatUntil, repeatWhen, replay, replay, replay, replay, replay, replay, replay, replay, replay, replay, replay, replay, replay, replay, replay, replay, replay, replay, retry, retry, retry, retry, retry, retryUntil, retryWhen, safeSubscribe, sample, sample, sample, sample, sample, sample, sample, scan, scan, scanWith, sequenceEqual, sequenceEqual, sequenceEqual, sequenceEqual, serialize, share, single, singleElement, singleOrError, singleOrErrorStage, singleStage, skip, skip, skip, skipLast, skipLast, skipLast, skipLast, skipLast, skipLast, skipUntil, skipWhile, sorted, sorted, startWith, startWith, startWith, startWith, startWithArray, startWithItem, startWithIterable, subscribe, subscribe, subscribe, subscribe, subscribe, subscribe, subscribe, subscribeActual, subscribeOn, subscribeOn, subscribeWith, switchIfEmpty, switchMap, switchMap, switchMapCompletable, switchMapCompletableDelayError, switchMapDelayError, switchMapDelayError, switchMapMaybe, switchMapMaybeDelayError, switchMapSingle, switchMapSingleDelayError, switchOnNext, switchOnNext, switchOnNextDelayError, switchOnNextDelayError, take, take, take, takeLast, takeLast, takeLast, takeLast, takeLast, takeLast, takeLast, takeLast, takeLast, takeUntil, takeUntil, takeWhile, test, test, test, throttleFirst, throttleFirst, throttleFirst, throttleLast, throttleLast, throttleLast, throttleLatest, throttleLatest, throttleLatest, throttleLatest, throttleLatest, throttleWithTimeout, throttleWithTimeout, throttleWithTimeout, timeInterval, timeInterval, timeInterval, timeInterval, timeout, timeout, timeout, timeout, timeout, timeout, timeout, timeout, timer, timer, timestamp, timestamp, timestamp, timestamp, to, toFuture, toList, toList, toList, toMap, toMap, toMap, toMultimap, toMultimap, toMultimap, toMultimap, toObservable, toSortedList, toSortedList, toSortedList, toSortedList, unsafeCreate, unsubscribeOn, using, using, window, window, window, window, window, window, window, window, window, window, window, window, window, window, window, window, window, withLatestFrom, withLatestFrom, withLatestFrom, withLatestFrom, withLatestFrom, withLatestFrom, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zipArray, zipWith, zipWith, zipWith, zipWith
@SchedulerSupport(value="none") public abstract void connect(@NonNull Consumer<? super Disposable> connection)
ConnectableFlowable
to begin emitting the items from its underlying
Flowable
to its Subscriber
s.
connection
- the action that receives the connection subscription before the subscription to source happens
allowing the caller to synchronously disconnect a synchronous sourceNullPointerException
- if connection
is null
@SchedulerSupport(value="none") public abstract void reset()
ConnectableFlowable
into its fresh state if it has terminated.
Calling this method on a fresh or active ConnectableFlowable
has no effect.
@NonNull @SchedulerSupport(value="none") public final @NonNull Disposable connect()
ConnectableFlowable
to begin emitting the items from its underlying
Flowable
to its Subscriber
s.
To disconnect from a synchronous source, use the connect(io.reactivex.rxjava3.functions.Consumer)
method.
@NonNull @CheckReturnValue @SchedulerSupport(value="none") @BackpressureSupport(value=PASS_THROUGH) public @NonNull Flowable<T> refCount()
Flowable
that stays connected to this ConnectableFlowable
as long as there
is at least one subscription to this ConnectableFlowable
.
ConnectableFlowable
's backpressure behavior.refCount
overload does not operate on any particular Scheduler
.Flowable
instancerefCount(int)
,
refCount(long, TimeUnit)
,
refCount(int, long, TimeUnit)
@CheckReturnValue @SchedulerSupport(value="none") @BackpressureSupport(value=PASS_THROUGH) @NonNull public final @NonNull Flowable<T> refCount(int subscriberCount)
ConnectableFlowable
if the number of subscribed
subscriber reaches the specified count and disconnect if all subscribers have unsubscribed.
ConnectableFlowable
's backpressure behavior.refCount
overload does not operate on any particular Scheduler
.History: 2.1.14 - experimental
subscriberCount
- the number of subscribers required to connect to the upstreamFlowable
instanceIllegalArgumentException
- if subscriberCount
is non-positive@CheckReturnValue @SchedulerSupport(value="io.reactivex:computation") @BackpressureSupport(value=PASS_THROUGH) @NonNull public final @NonNull Flowable<T> refCount(long timeout, @NonNull TimeUnit unit)
ConnectableFlowable
if the number of subscribed
subscriber reaches 1 and disconnect after the specified
timeout if all subscribers have unsubscribed.
ConnectableFlowable
's backpressure behavior.refCount
overload operates on the computation
Scheduler
.History: 2.1.14 - experimental
timeout
- the time to wait before disconnecting after all subscribers unsubscribedunit
- the time unit of the timeoutFlowable
instanceNullPointerException
- if unit
is null
refCount(long, TimeUnit, Scheduler)
@CheckReturnValue @SchedulerSupport(value="custom") @BackpressureSupport(value=PASS_THROUGH) @NonNull public final @NonNull Flowable<T> refCount(long timeout, @NonNull TimeUnit unit, @NonNull Scheduler scheduler)
ConnectableFlowable
if the number of subscribed
subscriber reaches 1 and disconnect after the specified
timeout if all subscribers have unsubscribed.
ConnectableFlowable
's backpressure behavior.refCount
overload operates on the specified Scheduler
.History: 2.1.14 - experimental
timeout
- the time to wait before disconnecting after all subscribers unsubscribedunit
- the time unit of the timeoutscheduler
- the target scheduler to wait on before disconnectingFlowable
instanceNullPointerException
- if unit
or scheduler
is null
@CheckReturnValue @SchedulerSupport(value="io.reactivex:computation") @BackpressureSupport(value=PASS_THROUGH) @NonNull public final @NonNull Flowable<T> refCount(int subscriberCount, long timeout, @NonNull TimeUnit unit)
ConnectableFlowable
if the number of subscribed
subscriber reaches the specified count and disconnect after the specified
timeout if all subscribers have unsubscribed.
ConnectableFlowable
's backpressure behavior.refCount
overload operates on the computation
Scheduler
.History: 2.1.14 - experimental
subscriberCount
- the number of subscribers required to connect to the upstreamtimeout
- the time to wait before disconnecting after all subscribers unsubscribedunit
- the time unit of the timeoutFlowable
instanceNullPointerException
- if unit
is null
IllegalArgumentException
- if subscriberCount
is non-positiverefCount(int, long, TimeUnit, Scheduler)
@CheckReturnValue @SchedulerSupport(value="custom") @BackpressureSupport(value=PASS_THROUGH) @NonNull public final @NonNull Flowable<T> refCount(int subscriberCount, long timeout, @NonNull TimeUnit unit, @NonNull Scheduler scheduler)
ConnectableFlowable
if the number of subscribed
subscriber reaches the specified count and disconnect after the specified
timeout if all subscribers have unsubscribed.
ConnectableFlowable
's backpressure behavior.refCount
overload operates on the specified Scheduler
.History: 2.1.14 - experimental
subscriberCount
- the number of subscribers required to connect to the upstreamtimeout
- the time to wait before disconnecting after all subscribers unsubscribedunit
- the time unit of the timeoutscheduler
- the target scheduler to wait on before disconnectingFlowable
instanceNullPointerException
- if unit
or scheduler
is null
IllegalArgumentException
- if subscriberCount
is non-positive@NonNull @CheckReturnValue @BackpressureSupport(value=PASS_THROUGH) @SchedulerSupport(value="none") public @NonNull Flowable<T> autoConnect()
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 Subscriber
s come
and go. Use refCount()
to renew a connection or dispose an active
connection when all Subscriber
s have cancelled their Subscription
s.
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.
ConnectableFlowable
's behavior.autoConnect
does not operate by default on a particular Scheduler
.Flowable
instance that automatically connects to this ConnectableFlowable
when the first Subscriber
subscribesrefCount()
,
autoConnect(int, Consumer)
@NonNull @CheckReturnValue @BackpressureSupport(value=PASS_THROUGH) @SchedulerSupport(value="none") public @NonNull Flowable<T> autoConnect(int numberOfSubscribers)
Flowable
that automatically connects (at most once) to this ConnectableFlowable
when the specified number of Subscriber
s 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 Subscriber
s come
and go. Use refCount()
to renew a connection or dispose an active
connection when all Subscriber
s have cancelled their Subscription
s.
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.
ConnectableFlowable
's behavior.autoConnect
does not operate by default on a particular Scheduler
.numberOfSubscribers
- the number of subscribers to await before calling connect
on the ConnectableFlowable
. A non-positive value indicates
an immediate connection.Flowable
instance that automatically connects to this ConnectableFlowable
when the specified number of Subscriber
s subscribe to it@NonNull @CheckReturnValue @BackpressureSupport(value=PASS_THROUGH) @SchedulerSupport(value="none") public @NonNull Flowable<T> autoConnect(int numberOfSubscribers, @NonNull Consumer<? super Disposable> connection)
Flowable
that automatically connects (at most once) to this ConnectableFlowable
when the specified number of Subscriber
s subscribe to it and calls the
specified callback with the Disposable
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 Subscriber
s come
and go. Use refCount()
to renew a connection or dispose an active
connection when all Subscriber
s have cancelled their Subscription
s.
ConnectableFlowable
's behavior.autoConnect
does not operate by default on a particular Scheduler
.numberOfSubscribers
- the number of subscribers to await before calling connect
on the ConnectableFlowable
. A non-positive value indicates
an immediate connection.connection
- the callback Consumer
that will receive the Disposable
representing the
established connectionFlowable
instance that automatically connects to this ConnectableFlowable
when the specified number of Subscriber
s subscribe to it and calls the
specified callback with the Disposable
associated with the established connectionNullPointerException
- if connection
is null