| 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() { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 return x + 100; | 26 return x + 100; |
| 27 }) | 27 }) |
| 28 .transform(new StreamTransformer.fromHandlers( | 28 .transform(new StreamTransformer.fromHandlers( |
| 29 handleError: (e, st, sink) { sink.add("error $e"); })) | 29 handleError: (e, st, sink) { sink.add("error $e"); })) |
| 30 .asBroadcastStream(); | 30 .asBroadcastStream(); |
| 31 stream.listen((x) { events.add("stream $x"); }); | 31 stream.listen((x) { events.add("stream $x"); }); |
| 32 }).listen((x) { events.add(x); }) | 32 }).listen((x) { events.add(x); }) |
| 33 .asFuture().then((_) { Expect.fail("Unexpected callback"); }); | 33 .asFuture().then((_) { Expect.fail("Unexpected callback"); }); |
| 34 stream.listen((x) { events.add("stream2 $x"); }); | 34 stream.listen((x) { events.add("stream2 $x"); }); |
| 35 controller.add(1); | 35 controller.add(1); |
| 36 // Errors are not allowed to traverse boundaries. This error should be | 36 // `addError` does not count as zone-traversal. It should be caught by |
| 37 // caught by the outer catchErrors. | 37 // the inner error handler. |
| 38 controller.addError(2); | 38 controller.addError("inner error"); |
| 39 new Future.error("caught by outer"); |
| 39 controller.close(); | 40 controller.close(); |
| 40 }).listen((x) { | 41 }).listen((x) { |
| 41 events.add("outer: $x"); | 42 events.add("outer: $x"); |
| 42 if (x == 2) done.complete(true); | 43 if (x == "caught by outer") done.complete(true); |
| 43 }, | 44 }, |
| 44 onDone: () { Expect.fail("Unexpected callback"); }); | 45 onDone: () { Expect.fail("Unexpected callback"); }); |
| 45 | 46 |
| 46 done.future.whenComplete(() { | 47 done.future.whenComplete(() { |
| 47 // Give handlers time to run. | 48 // Give handlers time to run. |
| 48 Timer.run(() { | 49 Timer.run(() { |
| 49 Expect.listEquals(["map 1", | 50 Expect.listEquals(["map 1", |
| 50 "stream 101", | 51 "stream 101", |
| 51 "stream2 101", | 52 "stream2 101", |
| 52 "outer: 2", | 53 "stream error inner error", |
| 54 "stream2 error inner error", |
| 55 "outer: caught by outer", |
| 53 ], | 56 ], |
| 54 events); | 57 events); |
| 55 asyncEnd(); | 58 asyncEnd(); |
| 56 }); | 59 }); |
| 57 }); | 60 }); |
| 58 } | 61 } |
| OLD | NEW |