disconnect method

Future<void> disconnect(
  1. String serverId
)

FR-CONN-004

Implementation

Future<void> disconnect(String serverId) async {
  final info = _connections[serverId];
  if (info == null) return;

  _logger.debug('Disconnecting', {'serverId': serverId});
  // Cancel the liveness listener first so tearing the client down does not
  // re-enter _handleTransportDrop for a disconnect we are performing.
  await info.disconnectSub?.cancel();
  info.disconnectSub = null;
  try {
    info.client?.disconnect();
  } catch (e, st) {
    _logger.warn('Disconnect error', {'serverId': serverId}, e);
    _logger.logError('Disconnect stack', e, st, {'serverId': serverId});
  }

  _connections.remove(serverId);
  notifyListeners();
}