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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 } catch (_, thrownStackTrace) { | 100 } catch (_, thrownStackTrace) { |
101 stackTrace = thrownStackTrace; | 101 stackTrace = thrownStackTrace; |
102 } | 102 } |
103 | 103 |
104 var completer = new Completer(); | 104 var completer = new Completer(); |
105 var subscription; | 105 var subscription; |
106 subscription = stream.listen((value) { | 106 subscription = stream.listen((value) { |
107 subscription.cancel(); | 107 subscription.cancel(); |
108 completer.complete(value); | 108 completer.complete(value); |
109 }, onError: (e) { | 109 }, onError: (e) { |
110 completer.completeError(e.error, e.stackTrace); | 110 completer.completeError(e); |
111 }, onDone: () { | 111 }, onDone: () { |
112 completer.completeError(new StateError("No elements"), stackTrace); | 112 completer.completeError(new StateError("No elements"), stackTrace); |
113 }, cancelOnError: true); | 113 }, cancelOnError: true); |
114 return completer.future; | 114 return completer.future; |
115 } | 115 } |
116 | 116 |
117 /// A function that can be called to cancel a [Stream] and send a done message. | 117 /// A function that can be called to cancel a [Stream] and send a done message. |
118 typedef void StreamCanceller(); | 118 typedef void StreamCanceller(); |
119 | 119 |
120 // TODO(nweiz): use a StreamSubscription when issue 9026 is fixed. | 120 // TODO(nweiz): use a StreamSubscription when issue 9026 is fixed. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } | 186 } |
187 | 187 |
188 /// Returns a string representation of [trace] that has the core and test frames | 188 /// Returns a string representation of [trace] that has the core and test frames |
189 /// folded together. | 189 /// folded together. |
190 String terseTraceString(StackTrace trace) { | 190 String terseTraceString(StackTrace trace) { |
191 return new Trace.from(trace).terse.foldFrames((frame) { | 191 return new Trace.from(trace).terse.foldFrames((frame) { |
192 return frame.package == 'scheduled_test' || frame.package == 'unittest' || | 192 return frame.package == 'scheduled_test' || frame.package == 'unittest' || |
193 frame.isCore; | 193 frame.isCore; |
194 }).toString().trim(); | 194 }).toString().trim(); |
195 } | 195 } |
OLD | NEW |