| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 heavy and light isolates can be mixed. | 5 // Dart test program for testing that heavy and light isolates can be mixed. |
| 6 | 6 |
| 7 #library('Mixed2Test'); | 7 #library('Mixed2Test'); |
| 8 #import('TestFramework.dart'); | 8 #import('TestFramework.dart'); |
| 9 | 9 |
| 10 // We want to send a message from the main-isolate to a chain of different | 10 // We want to send a message from the main-isolate to a chain of different |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 this.port.close(); | 26 this.port.close(); |
| 27 }); | 27 }); |
| 28 }); | 28 }); |
| 29 } | 29 } |
| 30 } | 30 } |
| 31 | 31 |
| 32 class HeavyIsolate1 extends Isolate { | 32 class HeavyIsolate1 extends Isolate { |
| 33 HeavyIsolate1() : super.heavy(); | 33 HeavyIsolate1() : super.heavy(); |
| 34 | 34 |
| 35 void main() { | 35 void main() { |
| 36 Promise<SendPort> light1 = new LightRedirect().spawn(); | 36 Future<SendPort> light1 = new LightRedirect().spawn(); |
| 37 Promise<SendPort> light2 = new LightRedirect().spawn(); | 37 Future<SendPort> light2 = new LightRedirect().spawn(); |
| 38 Promise<SendPort> light3 = new LightRedirect().spawn(); | 38 Future<SendPort> light3 = new LightRedirect().spawn(); |
| 39 | 39 |
| 40 this.port.receive((SendPort heavy2Light1Port, ignored) { | 40 this.port.receive((SendPort heavy2Light1Port, ignored) { |
| 41 light3.then((SendPort light3Port) { | 41 light3.then((SendPort light3Port) { |
| 42 light3Port.send(heavy2Light1Port, null); | 42 light3Port.send(heavy2Light1Port, null); |
| 43 light2.then((SendPort light2Port) { | 43 light2.then((SendPort light2Port) { |
| 44 light2Port.send(light3Port, null); | 44 light2Port.send(light3Port, null); |
| 45 light1.then((SendPort light1Port) { | 45 light1.then((SendPort light1Port) { |
| 46 light1Port.send(light2Port, null); | 46 light1Port.send(light2Port, null); |
| 47 // Next message we receive is the one that must go through the | 47 // Next message we receive is the one that must go through the |
| 48 // chain. | 48 // chain. |
| 49 this.port.receive((msg, SendPort replyTo) { | 49 this.port.receive((msg, SendPort replyTo) { |
| 50 light1Port.send(msg + 1, replyTo); | 50 light1Port.send(msg + 1, replyTo); |
| 51 this.port.close(); | 51 this.port.close(); |
| 52 }); | 52 }); |
| 53 }); | 53 }); |
| 54 }); | 54 }); |
| 55 }); | 55 }); |
| 56 }); | 56 }); |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 class HeavyIsolate2 extends Isolate { | 60 class HeavyIsolate2 extends Isolate { |
| 61 HeavyIsolate2() : super.heavy(); | 61 HeavyIsolate2() : super.heavy(); |
| 62 | 62 |
| 63 void main() { | 63 void main() { |
| 64 Promise<SendPort> light1 = new LightRedirect().spawn(); | 64 Future<SendPort> light1 = new LightRedirect().spawn(); |
| 65 Promise<SendPort> light2 = new LightRedirect().spawn(); | 65 Future<SendPort> light2 = new LightRedirect().spawn(); |
| 66 Promise<SendPort> light3 = new LightRedirect().spawn(); | 66 Future<SendPort> light3 = new LightRedirect().spawn(); |
| 67 | 67 |
| 68 this.port.receive((heavy3Port, replyWithLight1Port) { | 68 this.port.receive((heavy3Port, replyWithLight1Port) { |
| 69 light3.then((SendPort light3Port) { | 69 light3.then((SendPort light3Port) { |
| 70 light3Port.send(heavy3Port, null); | 70 light3Port.send(heavy3Port, null); |
| 71 light2.then((SendPort light2Port) { | 71 light2.then((SendPort light2Port) { |
| 72 light2Port.send(light3Port, null); | 72 light2Port.send(light3Port, null); |
| 73 light1.then((SendPort light1Port) { | 73 light1.then((SendPort light1Port) { |
| 74 light1Port.send(light2Port, null); | 74 light1Port.send(light2Port, null); |
| 75 replyWithLight1Port.send(light1Port, null); | 75 replyWithLight1Port.send(light1Port, null); |
| 76 this.port.close(); | 76 this.port.close(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 89 replyTo.send(msg + 499, null); | 89 replyTo.send(msg + 499, null); |
| 90 this.port.close(); | 90 this.port.close(); |
| 91 }); | 91 }); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 class HeavyIsolate3 extends Isolate { | 95 class HeavyIsolate3 extends Isolate { |
| 96 HeavyIsolate3() : super.heavy(); | 96 HeavyIsolate3() : super.heavy(); |
| 97 | 97 |
| 98 void main() { | 98 void main() { |
| 99 Promise<SendPort> pong = new LightPong().spawn(); | 99 Future<SendPort> pong = new LightPong().spawn(); |
| 100 this.port.receive((msg, replyTo) { | 100 this.port.receive((msg, replyTo) { |
| 101 pong.then((SendPort pongPort) { | 101 pong.then((SendPort pongPort) { |
| 102 pongPort.send(msg + 30, replyTo); | 102 pongPort.send(msg + 30, replyTo); |
| 103 this.port.close(); | 103 this.port.close(); |
| 104 }); | 104 }); |
| 105 }); | 105 }); |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 | 108 |
| 109 void test(TestExpectation expect) { | 109 void test(TestExpectation expect) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 125 })); | 125 })); |
| 126 })); | 126 })); |
| 127 })); | 127 })); |
| 128 })); | 128 })); |
| 129 })); | 129 })); |
| 130 } | 130 } |
| 131 | 131 |
| 132 main() { | 132 main() { |
| 133 runTests([test]); | 133 runTests([test]); |
| 134 } | 134 } |
| OLD | NEW |