| 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 import 'package:stack_trace/stack_trace.dart'; | 9 import 'package:stack_trace/stack_trace.dart'; |
| 10 | 10 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 /// then close. | 84 /// then close. |
| 85 /// | 85 /// |
| 86 /// If [broadcast] is true, a broadcast stream is returned. This assumes that | 86 /// If [broadcast] is true, a broadcast stream is returned. This assumes that |
| 87 /// the stream returned by [future] will be a broadcast stream as well. | 87 /// the stream returned by [future] will be a broadcast stream as well. |
| 88 /// [broadcast] defaults to false. | 88 /// [broadcast] defaults to false. |
| 89 Stream futureStream(Future<Stream> future, {bool broadcast: false}) { | 89 Stream futureStream(Future<Stream> future, {bool broadcast: false}) { |
| 90 var subscription; | 90 var subscription; |
| 91 var controller; | 91 var controller; |
| 92 | 92 |
| 93 future = future.catchError((e, stackTrace) { | 93 future = future.catchError((e, stackTrace) { |
| 94 if (controller == null) return; | 94 // Since [controller] is synchronous, it's likely that emitting an error |
| 95 controller.addError(e, stackTrace); | 95 // will cause it to be cancelled before we call close. |
| 96 controller.close(); | 96 if (controller != null) controller.addError(e, stackTrace); |
| 97 if (controller != null) controller.close(); |
| 97 controller = null; | 98 controller = null; |
| 98 }); | 99 }); |
| 99 | 100 |
| 100 onListen() { | 101 onListen() { |
| 101 future.then((stream) { | 102 future.then((stream) { |
| 102 if (controller == null) return; | 103 if (controller == null) return; |
| 103 subscription = stream.listen( | 104 subscription = stream.listen( |
| 104 controller.add, | 105 controller.add, |
| 105 onError: controller.addError, | 106 onError: controller.addError, |
| 106 onDone: controller.close); | 107 onDone: controller.close); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 } | 232 } |
| 232 | 233 |
| 233 /// Returns a string representation of [trace] that has the core and test frames | 234 /// Returns a string representation of [trace] that has the core and test frames |
| 234 /// folded together. | 235 /// folded together. |
| 235 String terseTraceString(StackTrace trace) { | 236 String terseTraceString(StackTrace trace) { |
| 236 return new Trace.from(trace).terse.foldFrames((frame) { | 237 return new Trace.from(trace).terse.foldFrames((frame) { |
| 237 return frame.package == 'scheduled_test' || frame.package == 'unittest' || | 238 return frame.package == 'scheduled_test' || frame.package == 'unittest' || |
| 238 frame.isCore; | 239 frame.isCore; |
| 239 }).toString().trim(); | 240 }).toString().trim(); |
| 240 } | 241 } |
| OLD | NEW |