ReactiveNetwork icon indicating copy to clipboard operation
ReactiveNetwork copied to clipboard

Better internet detection?

Open Kisty opened this issue 7 years ago • 3 comments

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.

Kisty avatar Oct 25 '18 16:10 Kisty

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.

pwittchen avatar Oct 25 '18 16:10 pwittchen

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...

Kisty avatar Oct 25 '18 16:10 Kisty

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.

pwittchen avatar Oct 25 '18 19:10 pwittchen