receiveResponse method

Future<Object?> receiveResponse(
  1. JsonRpcId id
)

Waits for and consumes one outbound response with id.

Server handshakes use this before writing the matching initialize request so the response cannot race subscription setup. A consumed response is not also published to an SSE or WebSocket route.

Implementation

Future<Object?> receiveResponse(JsonRpcId id) {
  if (_isClosed) {
    return Future<Object?>.error(
      _closeReason ?? StateError('ACP server connection is closed'),
    );
  }
  if (_responseWaiters.containsKey(id)) {
    return Future<Object?>.error(
      StateError('A response waiter already exists for $id'),
    );
  }
  if (_responseWaiters.length >= maximumPendingRoutes) {
    return Future<Object?>.error(
      StateError('ACP response waiter limit exceeded'),
    );
  }
  final completer = Completer<Object?>();
  _responseWaiters[id] = completer;
  return completer.future;
}