fromFuture<T> method Null safety

StreamSink<T> fromFuture<T>(
  1. Future<StreamSink<T>> sinkFuture
)

Convert a Future<StreamSink> to a StreamSink.

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

If the future completes with an error, the returned sink will instead be closed. Its Sink.done future will contain the error.

Implementation

static StreamSink<T> fromFuture<T>(Future<StreamSink<T>> sinkFuture) {
  var completer = StreamSinkCompleter<T>();
  sinkFuture.then(completer.setDestinationSink, onError: completer.setError);
  return completer.sink;
}