next property

Future<T> get next

Waits for the next element emitted by this stream, and returns it. If the stream emits an error, it will be propagated to the returned future. If the stream is closed before any data is emitted, it will throw a StateError.

Implementation

Future<T> get next {
  final completer = Completer<T>();
  StreamSubscription? subscription;
  subscription = innerStream.listen((data) {
    completer.complete(data);
    subscription?.cancel();
  }, onError: (e, s) {
    completer.completeError(e, s);
    subscription?.cancel();
  }, onDone: () {
    completer.completeError(StateError('Stream closed before any data was emitted'));
    subscription?.cancel();
  });
  return completer.future;
}