Chromium Code Reviews| 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 // Create a user-defined class in a new isolate. | 5 // Create a user-defined class in a new isolate. |
| 6 // | 6 // |
| 7 // Regression test for vm bug 2235: We were forgetting to finalize | 7 // Regression test for vm bug 2235: We were forgetting to finalize |
| 8 // classes in new isolates started using the v2 api. | 8 // classes in new isolates started using the v2 api. |
| 9 | 9 |
| 10 library spawn_tests; | 10 library spawn_tests; |
| 11 import 'dart:isolate'; | 11 import 'dart:isolate'; |
| 12 import '../../pkg/unittest/lib/unittest.dart'; | 12 import '../../pkg/unittest/lib/unittest.dart'; |
| 13 | 13 |
| 14 class MyClass { | 14 class MyClass { |
| 15 var myVar = 'there'; | 15 var myVar = 'there'; |
| 16 myFunc(msg) { | 16 myFunc(msg) { |
| 17 return '$msg $myVar'; | 17 return '$msg $myVar'; |
| 18 } | 18 } |
| 19 } | 19 } |
| 20 | 20 |
| 21 child() { | 21 child(args) { |
| 22 port.receive((msg, reply) { | 22 var reply = args[1]; |
| 23 reply.send('re: ${new MyClass().myFunc(msg)}'); | 23 var msg = args[0]; |
| 24 }); | 24 reply.send('re: ${new MyClass().myFunc(msg)}'); |
| 25 } | 25 } |
| 26 | 26 |
| 27 main() { | 27 main() { |
| 28 test('message - reply chain', () { | 28 test('message - reply chain', () { |
| 29 ReceivePort port = new ReceivePort(); | 29 ReceivePort port = new ReceivePort(); |
| 30 port.receive((msg, _) { | 30 port.listen((msg) { |
| 31 port.close(); | 31 port.close(); |
| 32 expect(msg, equals('re: hi there')); | 32 expect(msg, equals('re: hi there')); |
| 33 }); | 33 }); |
| 34 | 34 Isolate.spawn(child, ['hi', port.sendPort]); |
|
floitsch
2013/10/23 13:33:24
I prefer the sending before the listening.
Lasse Reichstein Nielsen
2013/10/24 10:26:01
Done.
| |
| 35 SendPort s = spawnFunction(child); | |
| 36 s.send('hi', port.toSendPort()); | |
| 37 }); | 35 }); |
| 38 } | 36 } |
| OLD | NEW |