| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 // Note: the following comment is used by test.dart to additionally compile the | 5 // Note: the following comment is used by test.dart to additionally compile the |
| 6 // other isolate's code. | 6 // other isolate's code. |
| 7 // OtherScripts=issue_21398_child_isolate.dart | 7 // OtherScripts=issue_21398_child_isolate.dart |
| 8 | 8 |
| 9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
| 10 import 'dart:async'; | 10 import 'dart:async'; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 reply.send(new FromMainIsolate()); | 24 reply.send(new FromMainIsolate()); |
| 25 } | 25 } |
| 26 | 26 |
| 27 main() { | 27 main() { |
| 28 var receive1 = new ReceivePort(); | 28 var receive1 = new ReceivePort(); |
| 29 var receive2 = new ReceivePort(); | 29 var receive2 = new ReceivePort(); |
| 30 | 30 |
| 31 // First spawn an isolate using spawnURI and have it | 31 // First spawn an isolate using spawnURI and have it |
| 32 // send back a "non-literal" like object. | 32 // send back a "non-literal" like object. |
| 33 asyncStart(); | 33 asyncStart(); |
| 34 Isolate.spawnUri(Uri.parse('issue_21398_child_isolate.dart'), | 34 Isolate.spawnUri(Uri.parse('issue_21398_child_isolate.dart'), [], |
| 35 [], | 35 [new FromMainIsolate(), receive1.sendPort]).catchError((error) { |
| 36 [new FromMainIsolate(), receive1.sendPort]).catchError( | 36 Expect.isTrue(error is ArgumentError); |
| 37 (error) { | 37 asyncEnd(); |
| 38 Expect.isTrue(error is ArgumentError); | 38 }); |
| 39 asyncStart(); |
| 40 Isolate |
| 41 .spawnUri( |
| 42 Uri.parse('issue_21398_child_isolate.dart'), [], receive1.sendPort) |
| 43 .then((isolate) { |
| 44 receive1.listen((msg) { |
| 45 Expect.stringEquals(msg, "Invalid Argument(s)."); |
| 46 receive1.close(); |
| 39 asyncEnd(); | 47 asyncEnd(); |
| 40 } | 48 }, onError: (e) => print('$e')); |
| 41 ); | 49 }); |
| 42 asyncStart(); | |
| 43 Isolate.spawnUri(Uri.parse('issue_21398_child_isolate.dart'), | |
| 44 [], | |
| 45 receive1.sendPort).then( | |
| 46 (isolate) { | |
| 47 receive1.listen( | |
| 48 (msg) { | |
| 49 Expect.stringEquals(msg, "Invalid Argument(s)."); | |
| 50 receive1.close(); | |
| 51 asyncEnd(); | |
| 52 }, | |
| 53 onError: (e) => print('$e') | |
| 54 ); | |
| 55 } | |
| 56 ); | |
| 57 | 50 |
| 58 // Now spawn an isolate using spawnFunction and send it a "non-literal" | 51 // Now spawn an isolate using spawnFunction and send it a "non-literal" |
| 59 // like object and also have the child isolate send back a "non-literal" | 52 // like object and also have the child isolate send back a "non-literal" |
| 60 // like object. | 53 // like object. |
| 61 asyncStart(); | 54 asyncStart(); |
| 62 Isolate.spawn(funcChild, | 55 Isolate.spawn(funcChild, [new FromMainIsolate(), receive2.sendPort]).then( |
| 63 [new FromMainIsolate(), receive2.sendPort]).then( | 56 (isolate) { |
| 64 (isolate) { | 57 receive2.listen((msg) { |
| 65 receive2.listen( | 58 Expect.isTrue(msg is FromMainIsolate); |
| 66 (msg) { | 59 Expect.equals(10, msg.fld); |
| 67 Expect.isTrue(msg is FromMainIsolate); | 60 receive2.close(); |
| 68 Expect.equals(10, msg.fld); | 61 asyncEnd(); |
| 69 receive2.close(); | 62 }, onError: (e) => print('$e')); |
| 70 asyncEnd(); | 63 }); |
| 71 }, | |
| 72 onError: (e) => print('$e') | |
| 73 ); | |
| 74 } | |
| 75 ); | |
| 76 } | 64 } |
| OLD | NEW |