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 asyncStart(); | 49 asyncStart(); |
50 RawReceivePort reply = new RawReceivePort(null); | 50 RawReceivePort reply = new RawReceivePort(null); |
51 RawReceivePort reply2 = new RawReceivePort(null); | 51 RawReceivePort reply2 = new RawReceivePort(null); |
52 // Create two isolates waiting for commands, with errors non-fatal. | 52 // Create two isolates waiting for commands, with errors non-fatal. |
53 Future iso1 = spawn(isomain1); | 53 Future iso1 = spawn(isomain1); |
54 Future iso2 = spawn(isomain1); | 54 Future iso2 = spawn(isomain1); |
55 Future.wait([iso1, iso2]).then((l) { | 55 Future.wait([iso1, iso2]).then((l) { |
56 var isolate1 = l[0][0]; | 56 var isolate1 = l[0][0]; |
57 var sendPort1 = l[0][1]; | 57 var sendPort1 = l[0][1]; |
58 var isolate2 = l[1][0]; | 58 var isolate2 = l[1][0]; |
59 var sendPort2 = l[1][1]; | 59 var sendPort2 = l[1][1]; |
60 // Capture errors from one isolate as stream. | 60 // Capture errors from one isolate as stream. |
61 Stream errors = isolate1.errors; // Broadcast stream, never a done message. | 61 Stream errors = isolate1.errors; // Broadcast stream, never a done message. |
62 int state = 1; | 62 int state = 1; |
63 var subscription; | 63 var subscription; |
64 subscription = errors.listen(null, onError: (error, stack) { | 64 subscription = errors.listen(null, onError: (error, stack) { |
65 switch (state) { | 65 switch (state) { |
66 case 1: | 66 case 1: |
67 Expect.equals(new ArgumentError("whoops").toString(), "$error"); | 67 Expect.equals(new ArgumentError("whoops").toString(), "$error"); |
68 state++; | 68 state++; |
69 break; | 69 break; |
70 case 2: | 70 case 2: |
71 Expect.equals(new RangeError.value(37).toString(), "$error"); | 71 Expect.equals(new RangeError.value(37).toString(), "$error"); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 sendPort1.send(0); | 106 sendPort1.send(0); |
107 sendPort2.send(0); | 107 sendPort2.send(0); |
108 sendPort1.send(1); | 108 sendPort1.send(1); |
109 sendPort2.send(1); | 109 sendPort2.send(1); |
110 sendPort1.send(2); | 110 sendPort1.send(2); |
111 sendPort2.send(2); | 111 sendPort2.send(2); |
112 sendPort1.send(3); | 112 sendPort1.send(3); |
113 sendPort2.send(3); | 113 sendPort2.send(3); |
114 }); | 114 }); |
115 } | 115 } |
116 | |
OLD | NEW |