OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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 // spawns multiple isolates and sends unresolved ports between them. | 5 // spawns multiple isolates and sends unresolved ports between them. |
6 #library('unresolved_ports'); | 6 #library('unresolved_ports'); |
7 #import('dart:isolate'); | 7 #import('dart:isolate'); |
8 #import('../../lib/unittest/unittest.dart'); | 8 #import('../../lib/unittest/unittest.dart'); |
9 | 9 |
10 // This test does the following: | 10 // This test does the following: |
(...skipping 17 matching lines...) Expand all Loading... |
28 bobIsolate() { | 28 bobIsolate() { |
29 port.receive((msg, reply) => reply.send( | 29 port.receive((msg, reply) => reply.send( |
30 '$msg\nBob says: we are all coming!')); | 30 '$msg\nBob says: we are all coming!')); |
31 } | 31 } |
32 | 32 |
33 main() { | 33 main() { |
34 test('Message chain with unresolved ports', () { | 34 test('Message chain with unresolved ports', () { |
35 ReceivePort port = new ReceivePort(); | 35 ReceivePort port = new ReceivePort(); |
36 port.receive(expectAsync2((msg, _) { | 36 port.receive(expectAsync2((msg, _) { |
37 expect(msg).equals('main says: Beth, find out if Tim is coming.' | 37 expect(msg).equals('main says: Beth, find out if Tim is coming.' |
38 + '\nBeth says: Tim are you coming? And Bob?' | 38 '\nBeth says: Tim are you coming? And Bob?' |
39 + '\nTim says: Can you tell "main" that we are all coming?' | 39 '\nTim says: Can you tell "main" that we are all coming?' |
40 + '\nBob says: we are all coming!'); | 40 '\nBob says: we are all coming!'); |
41 port.close(); | 41 port.close(); |
42 })); | 42 })); |
43 | 43 |
44 SendPort tim = spawnFunction(timIsolate); | 44 SendPort tim = spawnFunction(timIsolate); |
45 SendPort beth = spawnFunction(bethIsolate); | 45 SendPort beth = spawnFunction(bethIsolate); |
46 | 46 |
47 beth.send( | 47 beth.send( |
48 // because tim is created asynchronously, here we are sending an | 48 // because tim is created asynchronously, here we are sending an |
49 // unresolved port: | 49 // unresolved port: |
50 ['main says: Beth, find out if Tim is coming.', tim], | 50 ['main says: Beth, find out if Tim is coming.', tim], |
51 port.toSendPort()); | 51 port.toSendPort()); |
52 }); | 52 }); |
53 } | 53 } |
OLD | NEW |