Does anyone know why RxJava fight so much not havi...
# rx
u
Does anyone know why RxJava fight so much not having subscribers?. I want to just have the action finish regardless of anyone listening; and if they are they get result; else doesnt matter. Sort of like event buses used to do
d
Ask yourself why you have a stream of execution that you care about; but somehow the result doesn't matter? If you do have a result that matters; that should be handled in a subscriber. Or, if you don't have a clearly identifiable result - then presumably you want execution for one or more side-effects. In this case I'd look at refactoring your code, as you have discovered the Rx model implicitly promotes a functional style where reliance on side-effects should be avoided. A possible resolution to your immediate issue though is to use
.connect()
and not
.autoConnect()
.
autoConnect()
only subscribes to an up-stream
ConnectableObservable
when one or more down-stream Observers have subscribed. It sounds like you want an immediate, unconditional subscription, so just do
connect()
. This effectively is making a subscription with a subscriber which does nothing (when there are no other down-stream subscribers). Ensure to hold a reference to the returned
Disposable
and
.dispose()
it in an appropriate life-cycle callback.
u
Well technically you are right, its synching a database with remote api, so im sideeffecting to the db
The result technically is Unit, as in the synchronizaction finished, i.e. some sealed class of Result.Success
I actually want autoConnect, since UI triggers the syncing, I only want the syncing not to stop if the UI goes away