dispose method
Disposes the underlying socket client explicitly. Only use this, if you want to disconnect from the current server in favour of another one. If that's the case, create a new WebSocketLink instance.
Implementation
Future<void> dispose() async {
_isDisposed = true;
// Capture and clear before awaiting: a [connectOrReconnect] landing in this window must
// find no client to replace and no forwarder to cancel, or dispose would null a freshly
// installed client without ever closing it.
final client = _socketClient;
final forwarding = _connectionStateSubscription;
_socketClient = null;
_connectionStateSubscription = null;
await client?.dispose();
await forwarding?.cancel();
if (!_connectionState.isClosed) {
await _connectionState.close();
}
}