send method

Future<void> send(
  1. TRequest request
)

Sends the single request; may be called only once.

Implementation

Future<void> send(TRequest request) async {
  if (_requestSent) {
    throw StateError(
      'ServerStream allows only one request; it was already sent.',
    );
  }

  if (_logger.isInternal) {
    _logger.internal('Sending single request to server stream: $request');
  }

  try {
    _requestSent = true; // Set flag immediately to block duplicates.

    // Send the request via processor.
    await _processor.send(request);
    _logger.internal('Request sent via CallProcessor');

    // Finish sending to signal only one request (server-stream semantics).
    await _processor.finishSending();
  } catch (e, stackTrace) {
    _logger.error(
      'Failed to send request to server stream',
      error: e,
      stackTrace: stackTrace,
    );
    rethrow;
  }
}