channel<T> function

(LocalSender<T>, LocalReceiver<T>) channel<T>()

Creates a new channel, returning the Sender and LocalClosableReceiver. Each item T sent by the Sender will only be seen once by the LocalClosableReceiver. Even if the Sender calls close while the LocalClosableReceivers buffer is not empty, the LocalClosableReceiver will still yield the remaining items in the buffer until empty.

Implementation

(LocalSender<T>, LocalReceiver<T>) channel<T>() {
  // broadcast so no buffer
  StreamController<T> controller = StreamController<T>.broadcast();
  final sender = LocalSender._(controller.sink);
  final receiver = LocalReceiver._(controller.stream, () => sender.close());
  sender._receiver = receiver;
  return (sender, receiver);
}