OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // Dart test program for testing that isolates can spawn other isolates. | 5 // Dart test program for testing that isolates can spawn other isolates. |
6 | 6 |
7 library NestedSpawnTest; | 7 library NestedSpawnTest; |
8 import 'dart:isolate'; | 8 import 'dart:isolate'; |
9 import '../../pkg/unittest/lib/unittest.dart'; | 9 import '../../pkg/unittest/lib/unittest.dart'; |
10 | 10 |
11 void isolateA() { | 11 void isolateA(message) { |
12 port.receive((msg, replyTo) { | 12 message.add("isolateA"); |
13 expect(msg, "launch nested!"); | 13 Isolate.spawn(isolateB, message); |
14 SendPort p = spawnFunction(isolateB); | 14 } |
15 p.call("alive?").then((msg) { | 15 |
16 expect(msg, "and kicking"); | 16 void isolateB(message) { |
17 replyTo.send(499, null); | 17 message.add("isolateB"); |
18 port.close(); | 18 message[0].send(message); |
| 19 } |
| 20 |
| 21 main() { |
| 22 test("spawned isolates can spawn nested isolates", () { |
| 23 ReceivePort port = new ReceivePort(); |
| 24 Isolate.spawn(isolateA, [port.sendPort, "main"]); |
| 25 port.first.then((message) { |
| 26 expect("main", message[1]); |
| 27 expect("isolateA", message[2]); |
| 28 expect("isolateB", message[3]); |
19 }); | 29 }); |
20 }); | 30 }); |
21 } | 31 } |
22 | |
23 void isolateB() { | |
24 port.receive((msg, replyTo) { | |
25 expect(msg, "alive?"); | |
26 replyTo.send("and kicking", null); | |
27 port.close(); | |
28 }); | |
29 } | |
30 | |
31 | |
32 main() { | |
33 test("spawned isolates can spawn nested isolates", () { | |
34 SendPort port = spawnFunction(isolateA); | |
35 port.call("launch nested!").then(expectAsync1((msg) { | |
36 expect(msg, 499); | |
37 })); | |
38 }); | |
39 } | |
OLD | NEW |