| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import "package:expect/expect.dart"; | |
| 6 import 'dart:async'; | |
| 7 import 'dart:isolate'; | |
| 8 import 'catch_errors.dart'; | |
| 9 | |
| 10 main() { | |
| 11 // We keep a ReceivePort open until all tests are done. This way the VM will | |
| 12 // hang if the callbacks are not invoked and the test will time out. | |
| 13 var port = new ReceivePort(); | |
| 14 var events = []; | |
| 15 StreamController controller; | |
| 16 Stream stream; | |
| 17 // Test that the first listen on a `asBroadcastStream` determines the | |
| 18 // zone the subscription lives in. The inner listen happens first, and | |
| 19 // the outer listener must not see the error since it would cross a | |
| 20 // zone boundary. It is therefore given to the inner `catchErrors`. | |
| 21 catchErrors(() { | |
| 22 catchErrors(() { | |
| 23 controller = new StreamController(); | |
| 24 stream = controller.stream | |
| 25 .map((x) { | |
| 26 events.add("map $x"); | |
| 27 return x + 100; | |
| 28 }) | |
| 29 .asBroadcastStream(); | |
| 30 stream | |
| 31 .transform(new StreamTransformer( | |
| 32 handleError: (e, sink) => sink.add("error $e"))) | |
| 33 .listen((x) { events.add("stream $x"); }); | |
| 34 runAsync(() { | |
| 35 controller.add(1); | |
| 36 // Errors are not allowed to traverse boundaries, but in this case the | |
| 37 // first listener of the broadcast stream is in the same error-zone. So | |
| 38 // this should work. | |
| 39 controller.addError(2); | |
| 40 controller.close(); | |
| 41 }); | |
| 42 }).listen((x) { events.add(x); }) | |
| 43 .asFuture().then((_) { events.add("inner done"); }); | |
| 44 stream.listen((x) { events.add("stream2 $x"); }); | |
| 45 }).listen((x) { events.add("outer: $x"); }, | |
| 46 onDone: () { | |
| 47 Expect.listEquals(["map 1", | |
| 48 "stream 101", | |
| 49 "stream2 101", | |
| 50 "stream error 2", | |
| 51 2, // Caught by the inner `catchErrors`. | |
| 52 "inner done", | |
| 53 ], | |
| 54 events); | |
| 55 port.close(); | |
| 56 }); | |
| 57 } | |
| OLD | NEW |