| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 // Dart test program for testing that isolates can spawn other isolates. | |
| 6 | |
| 7 library NestedSpawnTest; | |
| 8 import 'dart:isolate'; | |
| 9 import '../../pkg/unittest/lib/unittest.dart'; | |
| 10 | |
| 11 void isolateA() { | |
| 12 IsolateSink replyTo; | |
| 13 bool isFirst = true; | |
| 14 stream.listen((msg) { | |
| 15 if (isFirst) { | |
| 16 isFirst = false; | |
| 17 replyTo = msg; | |
| 18 return; | |
| 19 } | |
| 20 expect(msg, "launch nested!"); | |
| 21 IsolateSink sink = streamSpawnFunction(isolateB); | |
| 22 MessageBox box = new MessageBox(); | |
| 23 sink.add(box.sink); | |
| 24 sink.add("alive?"); | |
| 25 box.stream.single.then((msg) { | |
| 26 expect(msg, "and kicking"); | |
| 27 replyTo.add(499); | |
| 28 replyTo.close(); | |
| 29 stream.close(); | |
| 30 }); | |
| 31 }); | |
| 32 } | |
| 33 | |
| 34 void isolateB() { | |
| 35 IsolateSink replyTo; | |
| 36 bool isFirst = true; | |
| 37 stream.listen((msg) { | |
| 38 if (isFirst) { | |
| 39 isFirst = false; | |
| 40 replyTo = msg; | |
| 41 return; | |
| 42 } | |
| 43 expect(msg, "alive?"); | |
| 44 replyTo.add("and kicking"); | |
| 45 replyTo.close(); | |
| 46 stream.close(); | |
| 47 }); | |
| 48 } | |
| 49 | |
| 50 | |
| 51 main() { | |
| 52 test("spawned isolates can spawn nested isolates", () { | |
| 53 MessageBox box = new MessageBox(); | |
| 54 IsolateSink sink = streamSpawnFunction(isolateA); | |
| 55 sink.add(box.sink); | |
| 56 sink.add("launch nested!"); | |
| 57 box.stream.single.then(expectAsync1((msg) { | |
| 58 expect(msg, 499); | |
| 59 })); | |
| 60 }); | |
| 61 } | |
| OLD | NEW |