-
Notifications
You must be signed in to change notification settings - Fork 589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Terminate ConnectionOperationQueue with proper exception #298
Conversation
As long as the user is interested in the connection the `ConnectionOperationQueue` will check the `DisconnectionRouterOutput` for exceptions that cause disconnection. If this exception is emitted the `ConnectionOperationQueue` terminates itself with the emitted error. If the user unsubscribes from the `RxBleDevice.establishConnection()` then the `ConnectionOperationQueue` terminates itself with the `BleDisconnectedException` as it was before this change.
.queue(operationDisconnect) | ||
.subscribe( | ||
Actions.empty(), | ||
Actions.<Throwable>toAction1(Actions.empty()) | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove empty line.
} | ||
}), | ||
disconnectionErrorOutputObservable = Observable.merge( | ||
disconnectionErrorInputRelay, | ||
adapterStateObservable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have it extracted to emitErrorWhenAdapterIsDisabled
or similar?
} | ||
}), | ||
disconnectionErrorOutputObservable = Observable.merge( | ||
disconnectionErrorInputRelay, | ||
adapterStateObservable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it rely on the initial state as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was not an issue till now. The DisconnectionRouter would not get created (@ConnectionScope) if the adapter is off
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
void onGattConnectionStateException(BleGattException disconnectedGattException) { | ||
disconnectionErrorRelay.call(disconnectedGattException); | ||
@Override | ||
public Observable<BleException> asExactObservable() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does it mean 'asExactObservable'? :) 😃 Could the method say something about the behavior?
private final Future<?> runnableFuture; | ||
private volatile boolean shouldRun = true; | ||
private volatile BleDisconnectedException bleDisconnectedException = null; | ||
private volatile BleException disconnectionException = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Effectively volatile
is not required here because of synchronization. Having synchronized access guarantees that the other thread will read the value after the previous has written it.
As long as the user is interested in the connection the
ConnectionOperationQueue
will check theDisconnectionRouterOutput
for exceptions that cause disconnection. If this exception is emitted theConnectionOperationQueue
terminates itself with the emitted error. If the user unsubscribes from theRxBleDevice.establishConnection()
then theConnectionOperationQueue
terminates itself with theBleDisconnectedException
as it was before this change. Fixes #297