Closed tomcheung closed 6 months ago
This is as designed, but it will take a bit of explaining. The TL:DR is that you should use .multicast(ReplaySubject<Int>.create(bufferSize: 1))
for this use-case.
The replay(1)
operator is a wrapper around the .multicast { ReplaySubject.create(bufferSize: 1) }
operator. This operator creates a Subject using the closure and when it's subscribed to, it binds the subscriber(s) to the subject. When connect is called, it binds the subject to the source and all the subscribers start receiving events.
When the connection is disposed, it destroys the Subject and therefore looses all the subscriptions. In essence, it only replays events to subscribers that subscribe while the source is emitting.
If you want to hold on to the values for longer, you need to use the multicast(_:)
that takes a Subject object rather than a closure that creates a Subject. When you do that, all connections will use the same Subject object which will exist as long as the connectable exists.
I see, thanks for detail explaination, i think it is clear enough and can close this issue
Short description of the issue: When a
ConnectableObservable
call.connect()
and dispose it, call.connect()
again will not able to start the subscriptionExpected outcome:
Not sure it is intended behaviour, but i expect it can be start the subscription again on when
.connect()
is called againWhat actually happens:
No event received
Self contained code example that reproduces the issue:
RxSwift/RxCocoa/RxBlocking/RxTest version/commit
6.6.0
Platform/Environment
How easy is to reproduce? (chances of successful reproduce after running the self contained code)
Xcode version:
:warning: Fields below are optional for general issues or in case those questions aren't related to your issue, but filling them out will increase the chances of getting your issue resolved. :warning:
Installation method: