disconnect method

Future<void> disconnect()

Closes the connection and releases all resources.

Implementation

Future<void> disconnect() async {
  if (!_connected) return;
  _connected = false;
  _log.info('Disconnecting from $this');

  await _socketSub?.cancel();
  _socketSub = null;
  _reader.close();

  try {
    _socket?.destroy();
  } catch (_) {}
  _socket = null;
}