bounded<T> static method

MpmcChannel<T> bounded<T>(
  1. int capacity, {
  2. String? metricsId,
})

Implementation

static MpmcChannel<T> bounded<T>(int capacity, {String? metricsId}) {
  if (capacity < 0) {
    throw ArgumentError.value(capacity, 'capacity', 'Must be >= 0');
  }

  final buf = (capacity == 0)
      ? RendezvousBuffer<T>()
      : BoundedBuffer<T>(capacity: capacity);
  final core = StandardChannelCore<T>(
    buf,
    allowMultiSenders: true,
    allowMultiReceivers: true,
    metricsId: metricsId,
  );
  final tx = core.attachSender((c) =>
      MpmcSender<T>._(c.id, c.createRemotePort(), metricsId: c.metricsId));
  final rx = core.attachReceiver((c) =>
      MpmcReceiver<T>._(c.id, c.createRemotePort(), metricsId: c.metricsId));
  return (tx, rx);
}