| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'null_stream_sink.dart'; | 7 import 'null_stream_sink.dart'; |
| 8 | 8 |
| 9 /// A [sink] where the destination is provided later. | 9 /// A [sink] where the destination is provided later. |
| 10 /// | 10 /// |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 /// Returns [sink] typed as a [_CompleterSink]. | 29 /// Returns [sink] typed as a [_CompleterSink]. |
| 30 _CompleterSink<T> get _sink => sink; | 30 _CompleterSink<T> get _sink => sink; |
| 31 | 31 |
| 32 /// Convert a `Future<StreamSink>` to a `StreamSink`. | 32 /// Convert a `Future<StreamSink>` to a `StreamSink`. |
| 33 /// | 33 /// |
| 34 /// This creates a sink using a sink completer, and sets the destination sink | 34 /// This creates a sink using a sink completer, and sets the destination sink |
| 35 /// to the result of the future when the future completes. | 35 /// to the result of the future when the future completes. |
| 36 /// | 36 /// |
| 37 /// If the future completes with an error, the returned sink will instead | 37 /// If the future completes with an error, the returned sink will instead |
| 38 /// be closed. Its [Sink.done] future will contain the error. | 38 /// be closed. Its [Sink.done] future will contain the error. |
| 39 static StreamSink/*<T>*/ fromFuture/*<T>*/( | 39 static StreamSink<T> fromFuture<T>(Future<StreamSink<T>> sinkFuture) { |
| 40 Future<StreamSink/*<T>*/> sinkFuture) { | 40 var completer = new StreamSinkCompleter<T>(); |
| 41 var completer = new StreamSinkCompleter/*<T>*/(); | 41 sinkFuture.then(completer.setDestinationSink, onError: completer.setError); |
| 42 sinkFuture.then(completer.setDestinationSink, | |
| 43 onError: completer.setError); | |
| 44 return completer.sink; | 42 return completer.sink; |
| 45 } | 43 } |
| 46 | 44 |
| 47 /// Sets a sink as the destination for events from the [StreamSinkCompleter]'s | 45 /// Sets a sink as the destination for events from the [StreamSinkCompleter]'s |
| 48 /// [sink]. | 46 /// [sink]. |
| 49 /// | 47 /// |
| 50 /// The completer's [sink] will act exactly as [destinationSink]. | 48 /// The completer's [sink] will act exactly as [destinationSink]. |
| 51 /// | 49 /// |
| 52 /// If the destination sink is set before events are added to [sink], further | 50 /// If the destination sink is set before events are added to [sink], further |
| 53 /// events are forwarded directly to [destinationSink]. | 51 /// events are forwarded directly to [destinationSink]. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 .catchError((_) {}); | 168 .catchError((_) {}); |
| 171 } | 169 } |
| 172 | 170 |
| 173 // If the user has already asked when the sink is done, connect the sink's | 171 // If the user has already asked when the sink is done, connect the sink's |
| 174 // done callback to that completer. | 172 // done callback to that completer. |
| 175 if (_doneCompleter != null) { | 173 if (_doneCompleter != null) { |
| 176 _doneCompleter.complete(sink.done); | 174 _doneCompleter.complete(sink.done); |
| 177 } | 175 } |
| 178 } | 176 } |
| 179 } | 177 } |
| OLD | NEW |