Open Kisty opened 5 years ago
You can do that now. It's described in documentation here: https://github.com/pwittchen/ReactiveNetwork#chaining-network-and-internet-connectivity-streams
Sometimes, switchMapSingle
may be a better choice than flatMapSingle
to discard first stream.
Thanks for getting back to me so quick! That makes sense, though what if there's lots of connection events in a small space of time, e.g. DISCONNECTED -> CONNECTING -> CONNECTED
then you'd fire off many internet checks. Couldn't you just filter CONNECTED
and DISCONNECTED
states? Also, putting such an API in the library might be a good idea? Although it may be subjective on when to react to network changes...
You can do that too right now. You can use RxJava operators like debounce(...)
, sample(...)
or something like that. Have a look at docs: https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables.
Just a thought, but could the internet connection check be a bit more intelligent and use the network check and then only check the internet if at least one is connected? Not sure if this would cause more problems than it solves but worth a thought.