| 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 fromFuture(Future<StreamSink> sinkFuture) { | 39 static StreamSink/*<T>*/ fromFuture/*<T>*/( |
| 40 var completer = new StreamSinkCompleter(); | 40 Future<StreamSink/*<T>*/> sinkFuture) { |
| 41 var completer = new StreamSinkCompleter/*<T>*/(); |
| 41 sinkFuture.then(completer.setDestinationSink, | 42 sinkFuture.then(completer.setDestinationSink, |
| 42 onError: completer.setError); | 43 onError: completer.setError); |
| 43 return completer.sink; | 44 return completer.sink; |
| 44 } | 45 } |
| 45 | 46 |
| 46 /// Sets a sink as the destination for events from the [StreamSinkCompleter]'s | 47 /// Sets a sink as the destination for events from the [StreamSinkCompleter]'s |
| 47 /// [sink]. | 48 /// [sink]. |
| 48 /// | 49 /// |
| 49 /// The completer's [sink] will act exactly as [destinationSink]. | 50 /// The completer's [sink] will act exactly as [destinationSink]. |
| 50 /// | 51 /// |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 .catchError((_) {}); | 170 .catchError((_) {}); |
| 170 } | 171 } |
| 171 | 172 |
| 172 // If the user has already asked when the sink is done, connect the sink's | 173 // If the user has already asked when the sink is done, connect the sink's |
| 173 // done callback to that completer. | 174 // done callback to that completer. |
| 174 if (_doneCompleter != null) { | 175 if (_doneCompleter != null) { |
| 175 _doneCompleter.complete(sink.done); | 176 _doneCompleter.complete(sink.done); |
| 176 } | 177 } |
| 177 } | 178 } |
| 178 } | 179 } |
| OLD | NEW |