SpscSender<T> class final

Efficient sender for SPSC channels.

Provides optimized message sending for single-producer scenarios. Designed for good performance and throughput.

Performance Optimizations

  • Efficient operations: Optimized communication path
  • Memory-friendly design: Minimizes unnecessary overheads
  • Optimized paths: Core operations streamlined for performance

Usage Guidelines

  • Only ONE thread should use this sender instance
  • Use trySend for non-blocking operations in time-critical paths
  • Use send when you can afford to wait for buffer space
  • Monitor isDisconnected for graceful shutdown detection

Example - High-frequency producer:

final (tx, rx) = Spsc.channel<double>(capacity: 8192);

// Time-critical producer loop
void produceData() {
  while (running) {
    final data = generateData();

    // Non-blocking send for real-time systems
    final result = tx.trySend(data);
    if (result is SendErrorFull) {
      // Handle backpressure - critical decision point
      onBufferFull(data);
    }
  }
}
Available extensions

Properties

hashCode int
The hash code for this object.
no setterinherited
isDisconnected bool
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

close() → void
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
send(T v) Future<SendResult>
sendAll(Iterable<T> it) Future<void>

Available on Sender<T>, provided by the SenderBatchX extension

Send all items with backpressure handling.
sendTimeout(T v, Duration d) Future<SendResult>

Available on Sender<T>, provided by the SenderTimeoutX extension

Send a value with a timeout to prevent indefinite blocking.
toString() String
A string representation of this object.
inherited
trySend(T v) SendResult
trySendAll(Iterable<T> it) Future<void>

Available on Sender<T>, provided by the SenderBatchX extension

Send all items using trySend without waiting (best-effort).

Operators

operator ==(Object other) bool
The equality operator.
inherited