disconnect method

Future<void> disconnect()

Close connection.

After calling the method, this instance of Client can no longer be used.

Implementation

Future<void> disconnect() async {
  if (_state == _ClientState.done) return;
  _logger.fine('Disconnecting');
  _changeState(_ClientState.done);
  final transportWasOpen = transport.isOpen;
  if (!transportWasOpen) {
    await transport.close();
  }
  await _connectStreamSubscription?.cancel();
  if (!_connectStreamController.isClosed) {
    await _connectStreamController.close();
  }
  if (!_controller.isClosed) {
    await _controller.close();
  }
  if (transportWasOpen) {
    await transport.close();
  }
}