| Index: tests/isolate/nested_spawn_stream2_test.dart
|
| diff --git a/tests/isolate/nested_spawn2_test.dart b/tests/isolate/nested_spawn_stream2_test.dart
|
| similarity index 69%
|
| copy from tests/isolate/nested_spawn2_test.dart
|
| copy to tests/isolate/nested_spawn_stream2_test.dart
|
| index a868084c2093c4785f2f63299ea7813422a6f82c..d21933e27efe3d373d491f7e314cd4ff9af75e84 100644
|
| --- a/tests/isolate/nested_spawn2_test.dart
|
| +++ b/tests/isolate/nested_spawn_stream2_test.dart
|
| @@ -10,12 +10,28 @@ library NestedSpawn2Test;
|
| import 'dart:isolate';
|
| import '../../pkg/unittest/lib/unittest.dart';
|
|
|
| +void _call(IsolateSink sink, msg, void onreceive(m, replyTo)) {
|
| + final box = new MessageBox();
|
| + sink.add([msg, box.sink]);
|
| + sink.close();
|
| + box.stream.single.then((msg) {
|
| + onreceive(msg[0], msg[1]);
|
| + });
|
| +}
|
| +
|
| +void _receive(IsolateStream stream, void onreceive(m, replyTo)) {
|
| + stream.single.then((msg) {
|
| + onreceive(msg[0], msg[1]);
|
| + });
|
| +}
|
| +
|
| void isolateA() {
|
| - port.receive((msg, replyTo) {
|
| + _receive(stream, (msg, replyTo) {
|
| expect(msg, "launch nested!");
|
| - SendPort p = spawnFunction(isolateB);
|
| - p.send(replyTo, null);
|
| - port.close();
|
| + IsolateSink sink = streamSpawnFunction(isolateB);
|
| + sink.add(replyTo);
|
| + sink.close();
|
| + stream.close();
|
| });
|
| }
|
|
|
| @@ -27,18 +43,8 @@ String msg4 = "4 now?";
|
| String msg5 = "5 Now.";
|
| 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);
|
| - });
|
| -}
|
| -
|
| void isolateB() {
|
| - port.receive((mainPort, replyTo) {
|
| - port.close();
|
| + stream.single.then((mainPort) {
|
| // Do a little ping-pong dance to give the intermediate isolate
|
| // time to die.
|
| _call(mainPort, msg0, ((msg, replyTo) {
|
| @@ -47,7 +53,8 @@ void isolateB() {
|
| expect(msg[0], "3");
|
| _call(replyTo, msg4, ((msg, replyTo) {
|
| expect(msg[0], "5");
|
| - replyTo.send(msg6, null);
|
| + replyTo.add(msg6);
|
| + replyTo.close();
|
| }));
|
| }));
|
| }));
|
| @@ -56,8 +63,8 @@ void isolateB() {
|
|
|
| main() {
|
| test("spawned isolate can spawn other isolates", () {
|
| - SendPort port = spawnFunction(isolateA);
|
| - _call(port, "launch nested!", expectAsync2((msg, replyTo) {
|
| + IsolateSink sink = streamSpawnFunction(isolateA);
|
| + _call(sink, "launch nested!", expectAsync2((msg, replyTo) {
|
| expect(msg[0], "0");
|
| _call(replyTo, msg1, expectAsync2((msg, replyTo) {
|
| expect(msg[0], "2");
|
|
|