Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: examples/dart/echo_client/lib/main.dart

Issue 2006093002: Dart: Futures -> Callbacks. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Merge Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « examples/dart/device_info/lib/main.dart ('k') | examples/dart/netcat/lib/main.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:mojo/application.dart'; 7 import 'package:mojo/application.dart';
8 import 'package:mojo/core.dart'; 8 import 'package:mojo/core.dart';
9 import 'package:_mojo_for_test_only/mojo/examples/echo.mojom.dart'; 9 import 'package:_mojo_for_test_only/mojo/examples/echo.mojom.dart';
10 10
11 class EchoClientApplication extends Application { 11 class EchoClientApplication extends Application {
12 final EchoInterfaceRequest _echo = new EchoInterfaceRequest(); 12 final EchoInterfaceRequest _echo = new EchoInterfaceRequest();
13 13
14 EchoClientApplication.fromHandle(MojoHandle handle) 14 EchoClientApplication.fromHandle(MojoHandle handle)
15 : super.fromHandle(handle) { 15 : super.fromHandle(handle) {
16 onError = ((_) { 16 onError = ((_) {
17 _closeHandles(); 17 _closeHandles();
18 }); 18 });
19 } 19 }
20 20
21 @override 21 @override
22 void initialize(List<String> arguments, String url) { 22 void initialize(List<String> arguments, String url) {
23 // See README.md for how to specify an alternate server on the command line. 23 // See README.md for how to specify an alternate server on the command line.
24 final server = (arguments.length > 0) ? arguments[1] : "dart_echo_server"; 24 final server = (arguments.length > 0) ? arguments[1] : "dart_echo_server";
25 connectToService(url.replaceAll("dart_echo_client", server), _echo); 25 connectToService(url.replaceAll("dart_echo_client", server), _echo);
26 26
27 _echo.echoString("hello world").then((response) { 27 var c = new Completer();
28 print("${response.value}"); 28 _echo.echoString("hello world", (String response) {
29 }).whenComplete(_closeHandles); 29 print("${response}");
30 c.complete(null);
31 });
32 c.future.whenComplete(_closeHandles);
30 } 33 }
31 34
32 Future _closeHandles() async { 35 Future _closeHandles() async {
33 await _echo.close(); 36 await _echo.close();
34 await close(); 37 await close();
35 MojoHandle.reportLeakedHandles(); 38 MojoHandle.reportLeakedHandles();
36 } 39 }
37 } 40 }
38 41
39 main(List args, Object handleToken) { 42 main(List args, Object handleToken) {
40 MojoHandle appHandle = new MojoHandle(handleToken); 43 MojoHandle appHandle = new MojoHandle(handleToken);
41 new EchoClientApplication.fromHandle(appHandle); 44 new EchoClientApplication.fromHandle(appHandle);
42 } 45 }
OLDNEW
« no previous file with comments | « examples/dart/device_info/lib/main.dart ('k') | examples/dart/netcat/lib/main.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698