ConnectableFlowable (RxJava Javadoc 3.1.10) (original) (raw)
A 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 Subscribers 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 callreset()
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.