unbounded<T> static method

(MpscSender<T>, MpscReceiver<T>) unbounded<T>({
  1. bool chunked = true,
  2. String? metricsId,
})

Creates an unbounded MPSC channel with unlimited capacity.

Producers never block - messages are queued indefinitely until consumed. Use when you need guaranteed delivery without backpressure.

Parameters:

  • chunked: Use chunked buffer for better memory efficiency (recommended)

Memory characteristics:

  • Chunked buffer: Allocates in 64-element chunks, cache-friendly
  • Standard buffer: Dynamic array with exponential growth
  • Memory usage: Grows with unconsumed message count

Example - Event collection:

final (eventTx, eventRx) = Mpsc.unbounded<LogEvent>();

// Multiple threads can send without blocking
void logInfo(String message) {
  eventTx.send(LogEvent.info(message)); // Never blocks
}

void logError(String message, Object error) {
  eventTx.send(LogEvent.error(message, error)); // Never blocks
}

// Single consumer processes all events
await for (final event in eventRx.stream()) {
  await writeToLog(event);
}

Implementation

static (MpscSender<T>, MpscReceiver<T>) unbounded<T>(
    {bool chunked = true, String? metricsId}) {
  final buf = chunked ? ChunkedBuffer<T>() : UnboundedBuffer<T>();
  final core = _MpscCore<T>(buf, metricsId: metricsId);
  final tx = core.attachSender((c) => MpscSender<T>._(c));
  final rx = core.attachReceiver((c) => MpscReceiver<T>._(c));
  return (tx, rx);
}