| 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 barback.utils; | 5 library barback.utils; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 /// A pair of values. | 9 /// A pair of values. |
| 10 class Pair<E, F> { | 10 class Pair<E, F> { |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 // We use a delayed future to allow runAsync events to finish. The | 172 // We use a delayed future to allow runAsync events to finish. The |
| 173 // Future.value or Future() constructors use runAsync themselves and would | 173 // Future.value or Future() constructors use runAsync themselves and would |
| 174 // therefore not wait for runAsync callbacks that are scheduled after invoking | 174 // therefore not wait for runAsync callbacks that are scheduled after invoking |
| 175 // this method. | 175 // this method. |
| 176 return new Future.delayed(Duration.ZERO, () => pumpEventQueue(times - 1)); | 176 return new Future.delayed(Duration.ZERO, () => pumpEventQueue(times - 1)); |
| 177 } | 177 } |
| 178 | 178 |
| 179 /// Like [new Future], but avoids issue 11911 by using [new Future.value] under | 179 /// Like [new Future], but avoids issue 11911 by using [new Future.value] under |
| 180 /// the covers. | 180 /// the covers. |
| 181 Future newFuture(callback()) => new Future.value().then((_) => callback()); | 181 Future newFuture(callback()) => new Future.value().then((_) => callback()); |
| 182 |
| 183 /// Returns a buffered stream that will emit the same values as the stream |
| 184 /// returned by [future] once [future] completes. If [future] completes to an |
| 185 /// error, the return value will emit that error and then close. |
| 186 Stream futureStream(Future<Stream> future) { |
| 187 var controller = new StreamController(sync: true); |
| 188 future.then((stream) { |
| 189 stream.listen( |
| 190 controller.add, |
| 191 onError: (error) => controller.addError(error), |
| 192 onDone: controller.close); |
| 193 }).catchError((e) { |
| 194 controller.addError(e); |
| 195 controller.close(); |
| 196 }); |
| 197 return controller.stream; |
| 198 } |
| OLD | NEW |