close method

  1. @override
Future<void> close()
override

Closes the connection

Implementation

@override
Future<void> close() {
  // Fail the queued writes now. On a connection whose sends stall, they
  // would otherwise wait their turn for minutes after the close, and so
  // would everything awaiting them (stream opens, closes, resets).
  final error = StateError('Connection closed');
  final inFlight = _inFlightWrite;
  if (inFlight != null && !inFlight.completer.isCompleted) {
    inFlight.completer.completeError(error);
  }
  while (_pendingWrites.isNotEmpty) {
    final pw = _pendingWrites.removeFirst();
    if (!pw.completer.isCompleted) pw.completer.completeError(error);
  }
  return _connection.close();
}