StreamSubscription listen()

in lib/src/lazy_stream.dart [28:49]


  StreamSubscription<T> listen(void Function(T)? onData,
      {Function? onError, void Function()? onDone, bool? cancelOnError}) {
    var callback = _callback;
    if (callback == null) {
      throw StateError('Stream has already been listened to.');
    }

    // Null out the callback before we invoke it to ensure that even while
    // running it, this can't be called twice.
    _callback = null;
    var result = callback();

    Stream<T> stream;
    if (result is Future<Stream<T>>) {
      stream = StreamCompleter.fromFuture(result);
    } else {
      stream = result;
    }

    return stream.listen(onData,
        onError: onError, onDone: onDone, cancelOnError: cancelOnError);
  }