Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Unified Diff: tests/isolate/nested_spawn2_test.dart

Issue 27215002: Very simple version of Isolates. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/isolate/mint_maker_test.dart ('k') | tests/isolate/nested_spawn_stream2_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/isolate/nested_spawn2_test.dart
diff --git a/tests/isolate/nested_spawn2_test.dart b/tests/isolate/nested_spawn2_test.dart
index a868084c2093c4785f2f63299ea7813422a6f82c..0c477ddbf3dd78f1925b2f969ed43acb1c21a997 100644
--- a/tests/isolate/nested_spawn2_test.dart
+++ b/tests/isolate/nested_spawn2_test.dart
@@ -10,12 +10,13 @@ library NestedSpawn2Test;
import 'dart:isolate';
import '../../pkg/unittest/lib/unittest.dart';
-void isolateA() {
- port.receive((msg, replyTo) {
- expect(msg, "launch nested!");
- SendPort p = spawnFunction(isolateB);
- p.send(replyTo, null);
- port.close();
+void isolateA(SendPort init) {
+ ReceivePort port = new ReceivePort();
+ init.send(port.sendPort);
+ port.first.then((message) {
+ expect(message[0], "launch nested!");
+ SendPort replyTo = message[1];
+ Isolate.spawn(isolateB, replyTo);
});
}
@@ -29,42 +30,41 @@ String msg6 = "6 Great. Bye";
void _call(SendPort p, msg, void onreceive(m, replyTo)) {
final replyTo = new ReceivePort();
- p.send(msg, replyTo.toSendPort());
- replyTo.receive((m, r) {
- replyTo.close();
- onreceive(m, r);
+ p.send([msg, replyTo.sendPort]);
+ replyTo.first.then((m) {
+ onreceive(m[0], m[1]);
});
}
-void isolateB() {
- port.receive((mainPort, replyTo) {
- port.close();
- // Do a little ping-pong dance to give the intermediate isolate
- // time to die.
- _call(mainPort, msg0, ((msg, replyTo) {
- expect(msg[0], "1");
- _call(replyTo, msg2, ((msg, replyTo) {
- expect(msg[0], "3");
- _call(replyTo, msg4, ((msg, replyTo) {
- expect(msg[0], "5");
- replyTo.send(msg6, null);
- }));
+void isolateB(SendPort mainPort) {
+ // Do a little ping-pong dance to give the intermediate isolate
+ // time to die.
+ _call(mainPort, msg0, ((msg, replyTo) {
+ expect(msg[0], "1");
+ _call(replyTo, msg2, ((msg, replyTo) {
+ expect(msg[0], "3");
+ _call(replyTo, msg4, ((msg, replyTo) {
+ expect(msg[0], "5");
+ replyTo.send([msg6, null]);
}));
}));
- });
+ }));
}
main() {
test("spawned isolate can spawn other isolates", () {
- SendPort port = spawnFunction(isolateA);
- _call(port, "launch nested!", expectAsync2((msg, replyTo) {
- expect(msg[0], "0");
- _call(replyTo, msg1, expectAsync2((msg, replyTo) {
- expect(msg[0], "2");
- _call(replyTo, msg3, expectAsync2((msg, replyTo) {
- expect(msg[0], "4");
- _call(replyTo, msg5, expectAsync2((msg, replyTo) {
- expect(msg[0], "6");
+ ReceivePort init = new ReceivePort();
+ Isolate.spawn(isolateA, init.sendPort);
+ init.first.then(expectAsync1((port) {
+ _call(port, "launch nested!", expectAsync2((msg, replyTo) {
+ expect(msg[0], "0");
+ _call(replyTo, msg1, expectAsync2((msg, replyTo) {
+ expect(msg[0], "2");
+ _call(replyTo, msg3, expectAsync2((msg, replyTo) {
+ expect(msg[0], "4");
+ _call(replyTo, msg5, expectAsync2((msg, _) {
+ expect(msg[0], "6");
+ }));
}));
}));
}));
« no previous file with comments | « tests/isolate/mint_maker_test.dart ('k') | tests/isolate/nested_spawn_stream2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698