OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /// Generic utility functions. Stuff that should possibly be in core. | 5 /// Generic utility functions. Stuff that should possibly be in core. |
6 library utils; | 6 library utils; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 import 'dart:isolate'; | 10 import 'dart:isolate'; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 completer.completeError(e); | 176 completer.completeError(e); |
177 }, onDone: () { | 177 }, onDone: () { |
178 completer.completeError(new StateError("No elements")); | 178 completer.completeError(new StateError("No elements")); |
179 }, cancelOnError: true); | 179 }, cancelOnError: true); |
180 return completer.future; | 180 return completer.future; |
181 } | 181 } |
182 | 182 |
183 /// Returns a wrapped version of [stream] along with a [StreamSubscription] that | 183 /// Returns a wrapped version of [stream] along with a [StreamSubscription] that |
184 /// can be used to control the wrapped stream. | 184 /// can be used to control the wrapped stream. |
185 Pair<Stream, StreamSubscription> streamWithSubscription(Stream stream) { | 185 Pair<Stream, StreamSubscription> streamWithSubscription(Stream stream) { |
186 var controller = new StreamController(sync: true); | 186 var controller = |
187 var controllerStream = stream.isBroadcast ? | 187 stream.isBroadcast ? new StreamController.broadcast(sync: true) |
188 controller.stream.asBroadcastStream() : | 188 : new StreamController(sync: true); |
189 controller.stream; | |
190 var subscription = stream.listen(controller.add, | 189 var subscription = stream.listen(controller.add, |
191 onError: controller.addError, | 190 onError: controller.addError, |
192 onDone: controller.close); | 191 onDone: controller.close); |
193 return new Pair<Stream, StreamSubscription>(controllerStream, subscription); | 192 return new Pair<Stream, StreamSubscription>(controller.stream, subscription); |
194 } | 193 } |
195 | 194 |
196 // TODO(nweiz): remove this when issue 7787 is fixed. | 195 // TODO(nweiz): remove this when issue 7787 is fixed. |
197 /// Creates two single-subscription [Stream]s that each emit all values and | 196 /// Creates two single-subscription [Stream]s that each emit all values and |
198 /// errors from [stream]. This is useful if [stream] is single-subscription but | 197 /// errors from [stream]. This is useful if [stream] is single-subscription but |
199 /// multiple subscribers are necessary. | 198 /// multiple subscribers are necessary. |
200 Pair<Stream, Stream> tee(Stream stream) { | 199 Pair<Stream, Stream> tee(Stream stream) { |
201 var controller1 = new StreamController(sync: true); | 200 var controller1 = new StreamController(sync: true); |
202 var controller2 = new StreamController(sync: true); | 201 var controller2 = new StreamController(sync: true); |
203 stream.listen((value) { | 202 stream.listen((value) { |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 error is FileException || | 502 error is FileException || |
504 error is HttpException || | 503 error is HttpException || |
505 error is HttpException || | 504 error is HttpException || |
506 error is LinkException || | 505 error is LinkException || |
507 error is MimeMultipartException || | 506 error is MimeMultipartException || |
508 error is OSError || | 507 error is OSError || |
509 error is ProcessException || | 508 error is ProcessException || |
510 error is SocketException || | 509 error is SocketException || |
511 error is WebSocketException; | 510 error is WebSocketException; |
512 } | 511 } |
OLD | NEW |