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

Side by Side Diff: mojo/dart/apptests/test_apps/pingpong/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
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/bindings.dart'; 8 import 'package:mojo/bindings.dart';
9 import 'package:mojo/core.dart'; 9 import 'package:mojo/core.dart';
10 10
(...skipping 29 matching lines...) Expand all
40 assert(_pingPongClient == null); 40 assert(_pingPongClient == null);
41 _pingPongClient = client; 41 _pingPongClient = client;
42 } 42 }
43 43
44 void ping(int pingValue) { 44 void ping(int pingValue) {
45 if (_pingPongClient != null) { 45 if (_pingPongClient != null) {
46 _pingPongClient.pong(pingValue + 1); 46 _pingPongClient.pong(pingValue + 1);
47 } 47 }
48 } 48 }
49 49
50 Future pingTargetUrl(String url, int count, 50 void pingTargetUrl(String url, int count, void callback(bool ok)) {
51 [Function responseFactory]) async {
52 if (_application == null) { 51 if (_application == null) {
53 return responseFactory(false); 52 callback(false);
53 return;
54 } 54 }
55 var completer = new Completer(); 55 var completer = new Completer();
56 var pingPongService = new PingPongServiceInterfaceRequest(); 56 var pingPongService = new PingPongServiceInterfaceRequest();
57 _application.connectToService(url, pingPongService); 57 _application.connectToService(url, pingPongService);
58 58
59 var pingPongClient = new PingPongClientImpl(count, completer); 59 var pingPongClient = new PingPongClientImpl(count, completer);
60 pingPongService.setClient(pingPongClient.client); 60 pingPongService.setClient(pingPongClient.client);
61 61
62 for (var i = 0; i < count; i++) { 62 for (var i = 0; i < count; i++) {
63 pingPongService.ping(i); 63 pingPongService.ping(i);
64 } 64 }
65 await completer.future; 65 completer.future.then((_) {
66 await pingPongService.close(); 66 callback(true);
67 67 pingPongService.close();
68 return responseFactory(true); 68 });
69 } 69 }
70 70
71 Future pingTargetService(PingPongServiceInterface service, int count, 71 void pingTargetService(
72 [Function responseFactory]) async { 72 PingPongServiceInterface service, int count, void callback(bool ok)) {
73 var pingPongService = service; 73 var pingPongService = service;
74 var completer = new Completer(); 74 var completer = new Completer();
75 var client = new PingPongClientImpl(count, completer); 75 var client = new PingPongClientImpl(count, completer);
76 pingPongService.setClient(client.client); 76 pingPongService.setClient(client.client);
77 77
78 for (var i = 0; i < count; i++) { 78 for (var i = 0; i < count; i++) {
79 pingPongService.ping(i); 79 pingPongService.ping(i);
80 } 80 }
81 await completer.future; 81 completer.future.then((_) {
82 await pingPongService.close(); 82 callback(true);
83 83 pingPongService.close();
84 return responseFactory(true); 84 });
85 } 85 }
86 86
87 getPingPongService(PingPongServiceInterfaceRequest service) { 87 getPingPongService(PingPongServiceInterfaceRequest service) {
88 var targetService = new PingPongServiceInterfaceRequest(); 88 var targetService = new PingPongServiceInterfaceRequest();
89 _application.connectToService("mojo:dart_pingpong_target", targetService); 89 _application.connectToService("mojo:dart_pingpong_target", targetService);
90 90
91 // Pass along the interface request to another implementation of the 91 // Pass along the interface request to another implementation of the
92 // service. 92 // service.
93 targetService.getPingPongService(service); 93 targetService.getPingPongService(service);
94 targetService.close(); 94 targetService.close();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 } 126 }
127 } 127 }
128 128
129 main(List args, Object handleToken) { 129 main(List args, Object handleToken) {
130 MojoHandle appHandle = new MojoHandle(handleToken); 130 MojoHandle appHandle = new MojoHandle(handleToken);
131 new PingPongApplication.fromHandle(appHandle) 131 new PingPongApplication.fromHandle(appHandle)
132 ..onError = ((_) { 132 ..onError = ((_) {
133 MojoHandle.reportLeakedHandles(); 133 MojoHandle.reportLeakedHandles();
134 }); 134 });
135 } 135 }
OLDNEW
« no previous file with comments | « mojo/dart/apptests/test_apps/echo/lib/main.dart ('k') | mojo/dart/apptests/test_apps/pingpong_target/lib/main.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698