OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // To run this app: | 5 // To run this app: |
6 // mojo_shell mojo:hello | 6 // mojo_shell mojo:hello |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 | 9 |
10 import 'package:mojo/public/dart/application.dart'; | 10 import 'package:mojo/application.dart'; |
11 import 'package:mojo/public/dart/bindings.dart'; | 11 import 'package:mojo/bindings.dart'; |
12 import 'package:mojo/public/dart/core.dart'; | 12 import 'package:mojo/core.dart'; |
13 | 13 |
14 class Hello extends Application { | 14 class Hello extends Application { |
15 Hello.fromHandle(MojoHandle handle) : super.fromHandle(handle); | 15 Hello.fromHandle(MojoHandle handle) : super.fromHandle(handle); |
16 | 16 |
17 void initialize(List<String> args, String url) { | 17 void initialize(List<String> args, String url) { |
18 print("$url Hello"); | 18 print("$url Hello"); |
19 | 19 |
20 // We expect to find the world mojo application at the same | 20 // We expect to find the world mojo application at the same |
21 // path as this application. | 21 // path as this application. |
22 var c = connectToApplication(url.replaceAll("hello", "world")); | 22 var c = connectToApplication(url.replaceAll("hello", "world")); |
23 | 23 |
24 // A call to close() here would cause this app to go down before the "world" | 24 // A call to close() here would cause this app to go down before the "world" |
25 // app has a chance to come up. Instead, we wait to close this app until | 25 // app has a chance to come up. Instead, we wait to close this app until |
26 // the "world" app comes up, does its print, and closes its end of the | 26 // the "world" app comes up, does its print, and closes its end of the |
27 // connection. | 27 // connection. |
28 c.onError = closeApplication; | 28 c.onError = closeApplication; |
29 } | 29 } |
30 | 30 |
31 Future closeApplication() async { | 31 Future closeApplication() async { |
32 await close(); | 32 await close(); |
33 assert(MojoHandle.reportLeakedHandles()); | 33 assert(MojoHandle.reportLeakedHandles()); |
34 } | 34 } |
35 } | 35 } |
36 | 36 |
37 main(List args) { | 37 main(List args) { |
38 MojoHandle appHandle = new MojoHandle(args[0]); | 38 MojoHandle appHandle = new MojoHandle(args[0]); |
39 new Hello.fromHandle(appHandle); | 39 new Hello.fromHandle(appHandle); |
40 } | 40 } |
OLD | NEW |