| 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 // Dart test program for testing isolate communication with | |
| 5 // typed objects. | |
| 6 // VMOptions=--checked | |
| 7 | |
| 8 library TypedMessageTest; | |
| 9 import "dart:async"; | |
| 10 import "package:expect/expect.dart"; | |
| 11 import "package:async_helper/async_helper.dart"; | |
| 12 import "dart:isolate"; | |
| 13 | |
| 14 void logMessages(SendPort replyTo) { | |
| 15 print("Starting log server."); | |
| 16 ReceivePort port = new ReceivePort(); | |
| 17 replyTo.send(port.sendPort); | |
| 18 port.first.then((List<int> message) { | |
| 19 print("Log $message"); | |
| 20 Expect.equals(5, message.length); | |
| 21 Expect.equals(0, message[0]); | |
| 22 Expect.equals(1, message[1]); | |
| 23 Expect.equals(2, message[2]); | |
| 24 Expect.equals(3, message[3]); | |
| 25 Expect.equals(4, message[4]); | |
| 26 port.close(); | |
| 27 replyTo.send(1); | |
| 28 print("Stopping log server."); | |
| 29 }); | |
| 30 } | |
| 31 | |
| 32 main() { | |
| 33 asyncStart(); | |
| 34 ReceivePort receivePort = new ReceivePort(); | |
| 35 Future<Isolate> remote = Isolate.spawn(logMessages, receivePort.sendPort); | |
| 36 List<int> msg = new List<int>(5); | |
| 37 for (int i = 0; i < 5; i++) { | |
| 38 msg[i] = i; | |
| 39 } | |
| 40 StreamIterator iterator = new StreamIterator(receivePort); | |
| 41 iterator.moveNext().then((b) { | |
| 42 SendPort sendPort = iterator.current; | |
| 43 sendPort.send(msg); | |
| 44 return iterator.moveNext(); | |
| 45 }).then((b) { | |
| 46 Expect.equals(1, iterator.current); | |
| 47 receivePort.close(); | |
| 48 asyncEnd(); | |
| 49 }); | |
| 50 } | |
| OLD | NEW |