When the WebSocket closes, it catches the error, yields disconnected, then loops back and calls ref.read(z21ServiceProvider), which returns the same closed instance... basically a loop which burns CPU.
|
@Riverpod(keepAlive: true) |
|
Stream<ConnectionStatus> connectionStatus(ref) async* { |
|
final timeout = ref.watch( |
|
settingsProvider.select( |
|
(config) => |
|
config.value?.httpReceiveTimeout ?? Config().httpReceiveTimeout, |
|
), |
|
); |
|
|
|
ConnectionStatus? previousStatus; |
|
|
|
while (true) { |
|
final z21 = ref.read(z21ServiceProvider); |
|
|
|
try { |
|
await for (final _ in z21.stream.timeout(Duration(seconds: timeout))) { |
|
if (previousStatus != ConnectionStatus.connected) { |
|
previousStatus = ConnectionStatus.connected; |
|
yield previousStatus; |
|
} |
|
} |
|
} catch (_) { |
|
if (previousStatus != ConnectionStatus.disconnected) { |
|
previousStatus = ConnectionStatus.disconnected; |
|
yield previousStatus; |
|
} |
|
} |
|
} |
|
} |
When the WebSocket closes, it catches the error, yields disconnected, then loops back and calls
ref.read(z21ServiceProvider), which returns the same closed instance... basically a loop which burns CPU.Frontend/lib/provider/connection_status.dart
Lines 27 to 55 in 3bce612