| 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 // spawns multiple isolates and sends unresolved ports between them. |
| 6 #library('unresolved_ports'); |
| 7 |
| 8 // This test does the following: |
| 9 // - main spawns two isolates: 'tim' and 'beth' |
| 10 // - 'tim' spawns an isolate: 'bob' |
| 11 // - main starts a message chain: |
| 12 // main -> beth -> tim -> bob -> main |
| 13 // by giving 'beth' a send-port to 'tim'. |
| 14 |
| 15 bethIsolate(ReceivePort port) { |
| 16 port.receive((msg, reply) => msg[1].send( |
| 17 "${msg[0]}\nBeth says: Tim are you coming? And Bob?", reply)); |
| 18 } |
| 19 |
| 20 timIsolate(ReceivePort port) { |
| 21 Isolate2 bob = new Isolate2.fromCode(bobIsolate); |
| 22 port.receive((msg, reply) => bob.sendPort.send( |
| 23 "$msg\nTim says: Can you tell 'main' that we are all coming?", reply)); |
| 24 } |
| 25 |
| 26 bobIsolate(ReceivePort port) { |
| 27 port.receive((msg, reply) => reply.send( |
| 28 "$msg\nBob says: we are all coming!")); |
| 29 } |
| 30 |
| 31 main() { |
| 32 ReceivePort port = new ReceivePort(); |
| 33 port.receive((msg, _) { |
| 34 Expect.equals("main says: Beth, find out if Tim is coming." |
| 35 + "\nBeth says: Tim are you coming? And Bob?" |
| 36 + "\nTim says: Can you tell 'main' that we are all coming?" |
| 37 + "\nBob says: we are all coming!", msg); |
| 38 port.close(); |
| 39 }); |
| 40 |
| 41 Isolate2 tim = new Isolate2.fromCode(timIsolate); |
| 42 Isolate2 beth = new Isolate2.fromCode(bethIsolate); |
| 43 |
| 44 beth.sendPort.send( |
| 45 // because tim is created asynchronously, here we are sending an |
| 46 // unresolved port: |
| 47 ["main says: Beth, find out if Tim is coming.", tim.sendPort], |
| 48 port.toSendPort()); |
| 49 } |
| OLD | NEW |