OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 exit_at_spawn; | 5 library exit_at_spawn; |
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"; |
11 | 11 |
| 12 // Isolate exiting immediately. |
12 isomain(args) {} | 13 isomain(args) {} |
13 | 14 |
| 15 // Isolate exiting after running microtasks. |
| 16 isomain2(args) { |
| 17 scheduleMicrotask((){}); |
| 18 } |
| 19 |
| 20 // Isolate exiting after running timers. |
| 21 isomain3(args) { |
| 22 new Timer(Duration.ZERO, (){}); |
| 23 } |
| 24 |
14 main(){ | 25 main(){ |
15 asyncStart(); | 26 asyncStart(); |
16 | 27 |
| 28 test(isomain); |
| 29 test(isomain2); |
| 30 test(isomain3); |
| 31 |
| 32 asyncEnd(); |
| 33 } |
| 34 |
| 35 void test(mainFunction) { |
| 36 asyncStart(); |
| 37 |
17 RawReceivePort exitPort = new RawReceivePort(); | 38 RawReceivePort exitPort = new RawReceivePort(); |
18 exitPort.handler = (message) { | 39 exitPort.handler = (message) { |
19 Expect.equals(null, message); | 40 Expect.equals(null, message); |
20 exitPort.close(); | 41 exitPort.close(); |
21 asyncEnd(); | 42 asyncEnd(); |
22 }; | 43 }; |
23 | 44 |
24 Isolate.spawn(isomain, | 45 Isolate.spawn(mainFunction, |
25 null, | 46 null, |
26 // Setup handler as part of spawn. | 47 // Setup handler as part of spawn. |
27 errorsAreFatal: false, | 48 errorsAreFatal: false, |
28 onExit: exitPort.sendPort); | 49 onExit: exitPort.sendPort); |
29 } | 50 } |
OLD | NEW |