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 library test; | |
6 | |
7 import 'package:expect/expect.dart'; | |
8 import 'dart:async'; | |
9 import 'dart:isolate'; | |
10 import "package:async_helper/async_helper.dart"; | |
11 | |
12 runTest() { | |
13 SendPort mainIsolate; | |
14 bool isFirst = true; | |
15 port.receive((msg, replyTo) { | |
16 if (isFirst) { | |
17 mainIsolate = msg; | |
18 isFirst = false; | |
19 throw new UnsupportedError("ignore exception"); | |
20 } | |
21 Expect.equals("message 2", msg); | |
22 mainIsolate.send("received"); | |
23 }); | |
24 } | |
25 | |
26 bool globalErrorHandler(IsolateUnhandledException e) { | |
27 return e.source is UnsupportedError && e.source.message == "ignore exception"; | |
28 } | |
29 | |
30 main() { | |
31 // Make sure this test doesn't last longer than 2 seconds. | |
32 var timer = new Timer(const Duration(seconds: 2), () { throw "failed"; }); | |
33 | |
34 var port = new ReceivePort(); | |
35 SendPort otherIsolate = spawnFunction(runTest, globalErrorHandler); | |
36 otherIsolate.send(port.toSendPort()); | |
37 otherIsolate.send("message 2"); | |
38 asyncStart(); | |
39 port.receive((msg, replyPort) { | |
40 Expect.equals("received", msg); | |
41 port.close(); | |
42 timer.cancel(); | |
43 asyncEnd(); | |
44 }); | |
45 } | |
OLD | NEW |