| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library utils; | 5 library utils; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 /// Configures [future] so that its result (success or exception) is passed on | 9 /// Configures [future] so that its result (success or exception) is passed on |
| 10 /// to [completer]. | 10 /// to [completer]. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 Stream errorStream(error) => new Future.immediateError(error).asStream(); | 45 Stream errorStream(error) => new Future.immediateError(error).asStream(); |
| 46 | 46 |
| 47 /// Returns a buffered stream that will emit the same values as the stream | 47 /// Returns a buffered stream that will emit the same values as the stream |
| 48 /// returned by [future] once [future] completes. If [future] completes to an | 48 /// returned by [future] once [future] completes. If [future] completes to an |
| 49 /// error, the return value will emit that error and then close. | 49 /// error, the return value will emit that error and then close. |
| 50 Stream futureStream(Future<Stream> future) { | 50 Stream futureStream(Future<Stream> future) { |
| 51 var controller = new StreamController(); | 51 var controller = new StreamController(); |
| 52 future.then((stream) { | 52 future.then((stream) { |
| 53 stream.listen( | 53 stream.listen( |
| 54 controller.add, | 54 controller.add, |
| 55 onError: (error) => controller.signalError(error), | 55 onError: (error) => controller.addError(error), |
| 56 onDone: controller.close); | 56 onDone: controller.close); |
| 57 }).catchError((e) { | 57 }).catchError((e) { |
| 58 controller.signalError(e); | 58 controller.addError(e); |
| 59 controller.close(); | 59 controller.close(); |
| 60 }); | 60 }); |
| 61 return controller.stream; | 61 return controller.stream; |
| 62 } | 62 } |
| OLD | NEW |