operator [] method

Stream<RpcTransportMessage> operator [](
  1. int streamId
)

The stream for streamId, creating its controller on first call.

Repeated calls return the SAME stream rather than a second controller: the endpoint layers may ask more than once for one call, and a second controller would silently receive nothing.

onCancel drops the entry, so a consumer that walks away before end-of-stream does not leave the controller behind.

Implementation

Stream<RpcTransportMessage> operator [](int streamId) {
  final existing = _controllers[streamId];
  if (existing != null) return existing.stream;
  final ctl = StreamController<RpcTransportMessage>(
    onCancel: () => _controllers.remove(streamId),
  );
  _controllers[streamId] = ctl;
  return ctl.stream;
}