OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library handle_error_test; | 5 library handle_error_test; |
6 | 6 |
7 import "dart:isolate"; | 7 import "dart:isolate"; |
8 import "dart:async"; | 8 import "dart:async"; |
9 import "package:async_helper/async_helper.dart"; | 9 import "package:async_helper/async_helper.dart"; |
10 import "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
(...skipping 26 matching lines...) Expand all Loading... |
37 return isolate.then((Isolate isolate) { | 37 return isolate.then((Isolate isolate) { |
38 isolate.setErrorsFatal(false); | 38 isolate.setErrorsFatal(false); |
39 isolate.resume(isolate.pauseCapability); | 39 isolate.resume(isolate.pauseCapability); |
40 Future result = reply.first.then((sendPort) { | 40 Future result = reply.first.then((sendPort) { |
41 return [isolate, sendPort]; | 41 return [isolate, sendPort]; |
42 }); | 42 }); |
43 return result; | 43 return result; |
44 }); | 44 }); |
45 } | 45 } |
46 | 46 |
47 main(){ | 47 main() { |
48 asyncStart(); | 48 asyncStart(); |
49 RawReceivePort reply = new RawReceivePort(null); | 49 RawReceivePort reply = new RawReceivePort(null); |
50 // Create two isolates waiting for commands, with errors non-fatal. | 50 // Create two isolates waiting for commands, with errors non-fatal. |
51 Future iso1 = spawn(isomain1); | 51 Future iso1 = spawn(isomain1); |
52 Future iso2 = spawn(isomain1); | 52 Future iso2 = spawn(isomain1); |
53 Future.wait([iso1, iso2]).then((l) { | 53 Future.wait([iso1, iso2]).then((l) { |
54 var isolate1 = l[0][0]; | 54 var isolate1 = l[0][0]; |
55 var sendPort1 = l[0][1]; | 55 var sendPort1 = l[0][1]; |
56 var isolate2 = l[1][0]; | 56 var isolate2 = l[1][0]; |
57 var sendPort2 = l[1][1]; | 57 var sendPort2 = l[1][1]; |
58 Stream errors = isolate1.errors; // Broadcast stream, never a done message. | 58 Stream errors = isolate1.errors; // Broadcast stream, never a done message. |
59 int state = 1; | 59 int state = 1; |
60 var subscription; | 60 var subscription; |
61 subscription = errors.listen(null, onError: (error, stack) { | 61 subscription = errors.listen(null, onError: (error, stack) { |
62 switch (state) { | 62 switch (state) { |
63 case 1: | 63 case 1: |
64 Expect.equals(new ArgumentError("whoops").toString(), "$error"); | 64 Expect.equals(new ArgumentError("whoops").toString(), "$error"); |
65 state++; | 65 state++; |
66 break; | 66 break; |
67 case 2: | 67 case 2: |
68 Expect.equals(new RangeError.value(37).toString(), "$error"); | 68 Expect.equals(new RangeError.value(37).toString(), "$error"); |
69 state++; | 69 state++; |
70 reply.close(); | 70 reply.close(); |
71 subscription.cancel(); | 71 subscription.cancel(); |
72 asyncEnd(); | 72 asyncEnd(); |
73 break; | 73 break; |
74 default: | 74 default: |
75 throw "Bad state for error: $state: $error"; | 75 throw "Bad state for error: $state: $error"; |
76 } | 76 } |
77 }); | 77 }); |
78 sendPort1.send(0); | 78 sendPort1.send(0); |
79 sendPort2.send(0); | 79 sendPort2.send(0); |
80 sendPort1.send(1); | 80 sendPort1.send(1); |
81 sendPort2.send(1); | 81 sendPort2.send(1); |
82 sendPort1.send(2); | 82 sendPort1.send(2); |
83 sendPort2.send(2); | 83 sendPort2.send(2); |
84 sendPort1.send(3); | 84 sendPort1.send(3); |
85 sendPort2.send(3); | 85 sendPort2.send(3); |
86 }); | 86 }); |
87 } | 87 } |
88 | |
OLD | NEW |