getConnection method

Future<ClientConnection> getConnection()

Returns a connection to this Channel's RPC endpoint.

The connection may be shared between multiple RPCs.

Implementation

Future<ClientConnection> getConnection() async {
  if (_isShutdown) throw GrpcError.unavailable('Channel shutting down.');
  if (!_connected) {
    _connection = createConnection();
    _connection.onStateChanged = (state) {
      if (_connectionStateStreamController.isClosed) {
        return;
      }
      _connectionStateStreamController.add(state);
    };
    _connected = true;
  }
  return _connection;
}