autoConnect method

  1. @override
R autoConnect({
  1. void connection(
    1. StreamSubscription<T> subscription
    )?,
})
override

Returns a Stream that automatically connects (at most once) to this ConnectableStream when the first Observer subscribes.

To disconnect from the source Stream, provide a connection callback and cancel the subscription at the appropriate time.

Implementation

@override
R autoConnect({
  void Function(StreamSubscription<T> subscription)? connection,
}) {
  if (_canReuse(_ConnectableStreamUse.autoConnect)) {
    return _subject as R;
  }

  _subject.onListen = () {
    final subscription = _connection;
    connection?.call(subscription);
  };
  _subject.onCancel = null;

  return _subject as R;
}