add method

void add(
  1. RpcTransportMessage message
)

Delivers message to its stream, closing that stream on end-of-stream.

The transport calls this AFTER putting the message on its own broadcast; the ordering matters only in that both must happen for every message.

Implementation

void add(RpcTransportMessage message) {
  final ctl = _controllers[message.streamId];
  if (ctl != null && !ctl.isClosed) {
    // A message the consumer is not reading yet waits here; see ownedPayload.
    ctl.add(
      ctl.hasListener && !ctl.isPaused ? message : ownedPayload(message),
    );
  }
  if (message.isEndOfStream) {
    final ended = _controllers.remove(message.streamId);
    if (ended != null && !ended.isClosed) unawaited(ended.close());
  }
}