| 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 import 'package:async_helper/async_helper.dart'; | 5 import 'package:async_helper/async_helper.dart'; |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'catch_errors.dart'; | 8 import 'catch_errors.dart'; |
| 9 | 9 |
| 10 main() { | 10 main() { |
| 11 asyncStart(); | 11 asyncStart(); |
| 12 Completer done = new Completer(); | 12 Completer done = new Completer(); |
| 13 | 13 |
| 14 var events = []; | 14 var events = []; |
| 15 StreamController controller; | 15 StreamController controller; |
| 16 Stream stream; | 16 Stream stream; |
| 17 // Test `StreamController.broadcast` streams. Note that the nested listener | 17 // Test `StreamController.broadcast` streams. Note that the nested listener |
| 18 // doesn't see the error, but the outer one does. | 18 // doesn't see the error, but the outer one does. |
| 19 catchErrors(() { | 19 catchErrors(() { |
| 20 catchErrors(() { | 20 catchErrors(() { |
| 21 controller = new StreamController.broadcast(); | 21 controller = new StreamController.broadcast(); |
| 22 controller.stream | 22 controller.stream |
| 23 .map((x) { | 23 .map((x) { |
| 24 events.add("map $x"); | 24 events.add("map $x"); |
| 25 return x + 100; | 25 return x + 100; |
| 26 }) | 26 }) |
| 27 .transform(new StreamTransformer( | 27 .transform(new StreamTransformer.fromHandlers( |
| 28 handleError: (e, sink) => sink.add("error $e"))) | 28 handleError: (e, st, sink) { sink.add("error $e"); })) |
| 29 .listen((x) { events.add("stream $x"); }); | 29 .listen((x) { events.add("stream $x"); }); |
| 30 }).listen((x) { events.add(x); }) | 30 }).listen((x) { events.add(x); }) |
| 31 .asFuture().then((_) { Expect.fail("Unexpected callback"); }); | 31 .asFuture().then((_) { Expect.fail("Unexpected callback"); }); |
| 32 controller.stream.listen((x) { events.add("stream2 $x"); }, | 32 controller.stream.listen((x) { events.add("stream2 $x"); }, |
| 33 onError: (x) { events.add("stream2 error $x"); }); | 33 onError: (x) { events.add("stream2 error $x"); }); |
| 34 controller.add(1); | 34 controller.add(1); |
| 35 // Errors are not allowed to traverse boundaries, but in this case the | 35 // Errors are not allowed to traverse boundaries, but in this case the |
| 36 // first listener of the broadcast stream is in the same error-zone. So | 36 // first listener of the broadcast stream is in the same error-zone. So |
| 37 // this should work. | 37 // this should work. |
| 38 controller.addError(2); | 38 controller.addError(2); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 50 "stream 101", | 50 "stream 101", |
| 51 "stream2 1", | 51 "stream2 1", |
| 52 "stream2 error 2", | 52 "stream2 error 2", |
| 53 "outer: 2", | 53 "outer: 2", |
| 54 ], | 54 ], |
| 55 events); | 55 events); |
| 56 asyncEnd(); | 56 asyncEnd(); |
| 57 }); | 57 }); |
| 58 }); | 58 }); |
| 59 } | 59 } |
| OLD | NEW |