OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016, 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 library isolate_errors; | |
6 | |
7 import "dart:isolate"; | |
8 import "dart:async"; | |
9 import "package:async_helper/async_helper.dart"; | |
10 import "package:expect/expect.dart"; | |
11 | |
12 isomain(arg) { | |
13 if (arg is SendPort) { | |
14 RawReceivePort wait = new RawReceivePort(); | |
15 wait.handler = (message) { | |
16 wait.close(); | |
17 isomain(message); | |
18 }; | |
19 arg.send(wait.sendPort); | |
20 } else { | |
21 throw new ArgumentError(arg); | |
22 } | |
23 } | |
24 | |
25 manyErrorsMain(int count) { | |
26 for (int i = 0; i < count; i++) { | |
27 Timer.run(() { throw "test#$i"; }); | |
28 } | |
29 } | |
30 | |
31 main(){ | |
32 asyncStart(); | |
33 { | |
34 asyncStart(); | |
35 Isolate.spawn(isomain, "test-1", paused: true).then((Isolate i) { | |
36 var errors = []; | |
37 i.errors.listen(null, | |
38 onError: (e, s) { | |
39 errors.add(e.toString().contains("test-1")); | |
40 }, | |
41 onDone: () { | |
42 Expect.listEquals([true], errors); | |
43 asyncEnd(); | |
44 }); | |
45 i.resume(i.pauseCapability); | |
46 }); | |
47 } | |
48 | |
49 { | |
50 asyncStart(); | |
51 var messageReceived = new Completer(); | |
52 var p = new RawReceivePort()..handler = messageReceived.complete; | |
53 Isolate.spawn(isomain, p.sendPort).then((i) { | |
54 messageReceived.future.then((port) { | |
55 p.close(); | |
56 // Isolate has started and is waiting for response. | |
57 var errors = []; | |
58 i.errors.listen(null, | |
59 onError: (e, s) { | |
60 errors.add(e.toString().contains("test-2")); | |
61 }, | |
62 onDone: () { | |
63 Expect.listEquals([true], errors); | |
64 asyncEnd(); | |
65 }); | |
66 port.send("test-2"); | |
67 }); | |
68 }); | |
69 } | |
70 | |
71 // { | |
floitsch
2016/12/07 16:12:00
Reenable or remove?
| |
72 // asyncStart(); | |
73 // Isolate.spawn(manyErrorsMain, 5, | |
74 // paused: true, errorsAreFatal: false).then((i) { | |
75 // var errors = []; | |
76 // i.errors.listen(null, | |
77 // onError: (e, s) { | |
78 // print(e); | |
79 // errors.add(e.toString().contains("test#${errors.length}")); | |
80 // }, | |
81 // onDone: () { | |
82 // print("done?"); | |
83 // Expect.listEquals([true, true, true, true, true], errors); | |
84 // asyncEnd(); | |
85 // }); | |
86 // i.resume(i.pauseCapability); | |
87 // }); | |
88 // } | |
89 | |
90 asyncEnd(); | |
91 } | |
OLD | NEW |