fromFuture<T> static method

Stream<T> fromFuture<T>(
  1. Future<Stream<T>> streamFuture
)

Convert a Future<Stream> to a Stream.

This creates a stream using a stream completer, and sets the source stream to the result of the future when the future completes.

If the future completes with an error, the returned stream will instead contain just that error.

Implementation

static Stream<T> fromFuture<T>(Future<Stream<T>> streamFuture) {
  var completer = StreamCompleter<T>();
  streamFuture.then(completer.setSourceStream, onError: completer.setError);
  return completer.stream;
}