What would be the recommended way of specifying a timeout for a connection or operation? Currently I use:
ConnectionObservable = mDevice
.establishConnection(mRxAppCompatActivity, false)
.timeout(DEFAULT_TIMEOUT_IN_MILLIS, TimeUnit.MILLISECONDS)
But I get the impression that occasionally the subsequent automatic closing and disconnecting of the gatt is not always done properly, as I sometimes have trouble reconnecting to the same device after that.
Would something like
.takeUntil(disconnectTrigger)
with disconnectTrigger.onNext() being triggered manually after the timeout be more recommended?
The .establishConnection()
function when called with autoConnect = false
will automatically fail after about 30 seconds.
Both options for disconnecting are equally acceptable. Usage of a particular solution is depending on the use-case in my opinion.
Note that those timeouts will be not affect much the operations that are already started - only exception is the connection operation can be cancelled but this functionality was merged into the master
branch recently. (https://github.com/Polidea/RxAndroidBle/commit/604853c4f39c5e8a19e02415c50b547b0befd0e7) The operations that are not yet processed will be removed from the operations queue.
I think that you may be suffering from a broken disconnection mechanism (it's hard to be sure with no logs). There is already a bug for this issue here: https://github.com/Polidea/RxAndroidBle/issues/63
Best Regards