| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// A single-subscription [stream] where the contents are provided later. | 7 /// A single-subscription [stream] where the contents are provided later. |
| 8 /// | 8 /// |
| 9 /// It is generally recommended that you never create a `Future<Stream>` | 9 /// It is generally recommended that you never create a `Future<Stream>` |
| 10 /// because you can just directly create a stream that doesn't do anything | 10 /// because you can just directly create a stream that doesn't do anything |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 final _stream = new _CompleterStream<T>(); | 27 final _stream = new _CompleterStream<T>(); |
| 28 | 28 |
| 29 /// Convert a `Future<Stream>` to a `Stream`. | 29 /// Convert a `Future<Stream>` to a `Stream`. |
| 30 /// | 30 /// |
| 31 /// This creates a stream using a stream completer, | 31 /// This creates a stream using a stream completer, |
| 32 /// and sets the source stream to the result of the future when the | 32 /// and sets the source stream to the result of the future when the |
| 33 /// future completes. | 33 /// future completes. |
| 34 /// | 34 /// |
| 35 /// If the future completes with an error, the returned stream will | 35 /// If the future completes with an error, the returned stream will |
| 36 /// instead contain just that error. | 36 /// instead contain just that error. |
| 37 static Stream/*<T>*/ fromFuture/*<T>*/(Future<Stream/*<T>*/> streamFuture) { | 37 static Stream<T> fromFuture<T>(Future<Stream<T>> streamFuture) { |
| 38 var completer = new StreamCompleter/*<T>*/(); | 38 var completer = new StreamCompleter<T>(); |
| 39 streamFuture.then(completer.setSourceStream, | 39 streamFuture.then(completer.setSourceStream, |
| 40 onError: completer.setError); | 40 onError: completer.setError); |
| 41 return completer.stream; | 41 return completer.stream; |
| 42 } | 42 } |
| 43 | 43 |
| 44 /// The stream of this completer. | 44 /// The stream of this completer. |
| 45 /// | 45 /// |
| 46 /// This stream is always a single-subscription stream. | 46 /// This stream is always a single-subscription stream. |
| 47 /// | 47 /// |
| 48 /// When a source stream is provided, its events will be forwarded to | 48 /// When a source stream is provided, its events will be forwarded to |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 _sourceStream = _controller.stream; // Mark stream as set. | 177 _sourceStream = _controller.stream; // Mark stream as set. |
| 178 _controller.close(); | 178 _controller.close(); |
| 179 } | 179 } |
| 180 | 180 |
| 181 // Creates the [_controller]. | 181 // Creates the [_controller]. |
| 182 void _createController() { | 182 void _createController() { |
| 183 assert(_controller == null); | 183 assert(_controller == null); |
| 184 _controller = new StreamController<T>(sync: true); | 184 _controller = new StreamController<T>(sync: true); |
| 185 } | 185 } |
| 186 } | 186 } |
| OLD | NEW |