| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2014, 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 import "dart:isolate"; |
| 6 import "dart:async"; |
| 7 import "package:expect/expect.dart"; |
| 8 import "package:async_helper/async_helper.dart"; |
| 9 |
| 10 isomain1(replyPort) { |
| 11 RawReceivePort port = new RawReceivePort(); |
| 12 port.handler = (v) { |
| 13 replyPort.send(v); |
| 14 if (v == 0) port.close(); |
| 15 }; |
| 16 replyPort.send(port.sendPort); |
| 17 } |
| 18 |
| 19 void main(){ |
| 20 asyncStart(); |
| 21 var completer = new Completer(); // Completed by first reply from isolate. |
| 22 RawReceivePort reply = new RawReceivePort(completer.complete); |
| 23 Isolate.spawn(isomain1, reply.sendPort).then((Isolate isolate) { |
| 24 List result = []; |
| 25 completer.future.then((echoPort) { |
| 26 reply.handler = (v) { |
| 27 result.add(v); |
| 28 if (v == 0) { |
| 29 Expect.listEquals(["alive", "control", "event"], |
| 30 result.where((x) => x is String).toList()); |
| 31 Expect.listEquals([4, 3, 2, 1, 0], |
| 32 result.where((x) => x is int).toList()); |
| 33 Expect.isTrue(result.indexOf("alive") < result.indexOf(3)); |
| 34 Expect.isTrue(result.indexOf("control") < result.indexOf(2)); |
| 35 int eventIndex = result.indexOf("event"); |
| 36 Expect.isTrue(eventIndex > result.indexOf(2)); |
| 37 Expect.isTrue(eventIndex < result.indexOf(1)); |
| 38 reply.close(); |
| 39 asyncEnd(); |
| 40 } |
| 41 }; |
| 42 echoPort.send(4); |
| 43 SendPort createPingPort(message) { |
| 44 var pingPort = new RawReceivePort(); |
| 45 pingPort.handler = (_) { |
| 46 result.add(message); |
| 47 pingPort.close(); |
| 48 }; |
| 49 return pingPort.sendPort; |
| 50 } |
| 51 isolate.ping(createPingPort("alive"), Isolate.PING_ALIVE); |
| 52 echoPort.send(3); |
| 53 isolate.ping(createPingPort("control"), Isolate.PING_CONTROL); |
| 54 echoPort.send(2); |
| 55 isolate.ping(createPingPort("event"), Isolate.PING_EVENT); |
| 56 echoPort.send(1); |
| 57 echoPort.send(0); |
| 58 }); |
| 59 }); |
| 60 } |
| OLD | NEW |