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:async_helper/async_helper.dart'; | |
6 import "package:expect/expect.dart"; | |
7 import 'dart:async'; | |
8 import 'catch_errors.dart'; | |
9 | |
10 main() { | |
11 asyncStart(); | |
12 Completer done = new Completer(); | |
13 | |
14 var events = []; | |
15 var controller = new StreamController(); | |
16 // Test that stream errors, as a result of bad user-code (`map`) are correctly | |
17 // caught by `catchErrors`. Note that the values are added outside both | |
18 // `catchErrors`, but since the `listen` happens in the most nested | |
19 // `catchErrors` it is caught there. | |
20 catchErrors(() { | |
21 catchErrors(() { | |
22 controller.stream.map((x) { | |
23 throw x; | |
24 }).listen((x) { | |
25 // Should not happen. | |
26 events.add("bad: $x"); | |
27 }); | |
28 }).listen((x) { | |
29 events.add("caught: $x"); | |
30 if (x == 4) done.complete(true); | |
31 }, onDone: () { | |
32 Expect.fail("Unexpected callback"); | |
33 }); | |
34 }).listen((x) { | |
35 events.add("outer: $x"); | |
36 }, onDone: () { | |
37 Expect.fail("Unexpected callback"); | |
38 }); | |
39 | |
40 done.future.whenComplete(() { | |
41 // Give handlers time to run. | |
42 Timer.run(() { | |
43 Expect.listEquals([ | |
44 "caught: 1", | |
45 "caught: 2", | |
46 "caught: 3", | |
47 "caught: 4", | |
48 ], events); | |
49 asyncEnd(); | |
50 }); | |
51 }); | |
52 | |
53 [1, 2, 3, 4].forEach(controller.add); | |
54 controller.close(); | |
55 } | |
OLD | NEW |