-
Notifications
You must be signed in to change notification settings - Fork 7
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
fix: Canceling a connectionState subscription results in hang #14
Comments
Can I get more information about this.
|
Sure, in my app I connect as follows: Future<void> connect(
{Function? onDisconnect, Duration timeout = const Duration(seconds: 35)}) async {
try {
// perform the connection
Stopwatch stopwatch = Stopwatch()..start();
await _device.connect(timeout: timeout, mtu: 517);
stopwatch.stop();
// listen for mtu changes
final mtuSubscription = _device.mtu.listen((mtu) => _mtu = mtu);
_device.cancelWhenDisconnected(mtuSubscription);
// discover services
_services = await _device.discoverServices(timeout: (timeout - stopwatch.elapsed).inSeconds);
} catch (e) {
await _device.disconnect(queue: false).catchError((e) {});
log.w(e);
throw Exception('FBP connect failed: $e');
}
// listen for disconnect
_disconnectSubscription = _device.connectionState.listen((state) {
if (state == fbp.BluetoothConnectionState.disconnected) {
onDisconnect?.call();
}
});
_device.cancelWhenDisconnected(_disconnectSubscription!, next: true, delayed: true);
} After connecting, I test several characteristic writes. If they fail, I call this disconnect function: Future<void> disconnect({bool withCallback = true}) async {
try {
if (!withCallback) {
await _disconnectSubscription?.cancel();
}
await _device.disconnect();
} catch (e) {
log.w(e);
}
} The point here is to cancel the connectionState subscription before calling |
It may be related with this post: I'll take a deeper look into the issues. |
Could be related to this code? https://github.com/chan150/flutter_blue_plus_windows/blob/master/lib/src/windows/bluetooth_device_windows.dart#L181-L183 A |
Description
Awaiting a connectionState subscription cancellation never completes.
Steps To Reproduce
Expected Behavior
Expected behavior is that the subscription can be canceled so that the app can disconnect from the device without calling
onConnectionState
.Additional Context
This code works on Android using the same version of Flutter Blue Plus (1.33.2)
The text was updated successfully, but these errors were encountered: