| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 /// the wrapped stream. Unlike [StreamSubscription], this canceller will send a | 126 /// the wrapped stream. Unlike [StreamSubscription], this canceller will send a |
| 127 /// "done" message to the wrapped stream. | 127 /// "done" message to the wrapped stream. |
| 128 Pair<Stream, StreamCanceller> streamWithCanceller(Stream stream) { | 128 Pair<Stream, StreamCanceller> streamWithCanceller(Stream stream) { |
| 129 var controller = new StreamController(); | 129 var controller = new StreamController(); |
| 130 var controllerStream = stream.isBroadcast ? | 130 var controllerStream = stream.isBroadcast ? |
| 131 controller.stream.asBroadcastStream() : | 131 controller.stream.asBroadcastStream() : |
| 132 controller.stream; | 132 controller.stream; |
| 133 var subscription = stream.listen((value) { | 133 var subscription = stream.listen((value) { |
| 134 if (!controller.isClosed) controller.add(value); | 134 if (!controller.isClosed) controller.add(value); |
| 135 }, onError: (error) { | 135 }, onError: (error) { |
| 136 if (!controller.isClosed) controller.signalError(error); | 136 if (!controller.isClosed) controller.addError(error); |
| 137 }, onDone: controller.close); | 137 }, onDone: controller.close); |
| 138 return new Pair<Stream, StreamCanceller>(controllerStream, controller.close); | 138 return new Pair<Stream, StreamCanceller>(controllerStream, controller.close); |
| 139 } | 139 } |
| 140 | 140 |
| 141 // TODO(nweiz): remove this when issue 7787 is fixed. | 141 // TODO(nweiz): remove this when issue 7787 is fixed. |
| 142 /// Creates two single-subscription [Stream]s that each emit all values and | 142 /// Creates two single-subscription [Stream]s that each emit all values and |
| 143 /// errors from [stream]. This is useful if [stream] is single-subscription but | 143 /// errors from [stream]. This is useful if [stream] is single-subscription but |
| 144 /// multiple subscribers are necessary. | 144 /// multiple subscribers are necessary. |
| 145 Pair<Stream, Stream> tee(Stream stream) { | 145 Pair<Stream, Stream> tee(Stream stream) { |
| 146 var controller1 = new StreamController(); | 146 var controller1 = new StreamController(); |
| 147 var controller2 = new StreamController(); | 147 var controller2 = new StreamController(); |
| 148 stream.listen((value) { | 148 stream.listen((value) { |
| 149 controller1.add(value); | 149 controller1.add(value); |
| 150 controller2.add(value); | 150 controller2.add(value); |
| 151 }, onError: (error) { | 151 }, onError: (error) { |
| 152 controller1.signalError(error); | 152 controller1.addError(error); |
| 153 controller2.signalError(error); | 153 controller2.addError(error); |
| 154 }, onDone: () { | 154 }, onDone: () { |
| 155 controller1.close(); | 155 controller1.close(); |
| 156 controller2.close(); | 156 controller2.close(); |
| 157 }); | 157 }); |
| 158 return new Pair<Stream, Stream>(controller1.stream, controller2.stream); | 158 return new Pair<Stream, Stream>(controller1.stream, controller2.stream); |
| 159 } | 159 } |
| 160 | 160 |
| 161 /// Takes a simple data structure (composed of [Map]s, [Iterable]s, scalar | 161 /// Takes a simple data structure (composed of [Map]s, [Iterable]s, scalar |
| 162 /// objects, and [Future]s) and recursively resolves all the [Future]s contained | 162 /// objects, and [Future]s) and recursively resolves all the [Future]s contained |
| 163 /// within. Completes with the fully resolved structure. | 163 /// within. Completes with the fully resolved structure. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 191 } | 191 } |
| 192 | 192 |
| 193 /// Returns a string representation of [trace] that has the core and test frames | 193 /// Returns a string representation of [trace] that has the core and test frames |
| 194 /// folded together. | 194 /// folded together. |
| 195 String terseTraceString(StackTrace trace) { | 195 String terseTraceString(StackTrace trace) { |
| 196 return new Trace.from(trace).terse.foldFrames((frame) { | 196 return new Trace.from(trace).terse.foldFrames((frame) { |
| 197 return frame.package == 'scheduled_test' || frame.package == 'unittest' || | 197 return frame.package == 'scheduled_test' || frame.package == 'unittest' || |
| 198 frame.isCore; | 198 frame.isCore; |
| 199 }).toString().trim(); | 199 }).toString().trim(); |
| 200 } | 200 } |
| OLD | NEW |