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

Side by Side Diff: tests/isolate/src/MintMakerTest.dart

Issue 9652001: SendPort + ReceivePort changes: (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « tests/isolate/src/MessageTest.dart ('k') | tests/isolate/src/Mixed2Test.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 (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 // Things that should be "auto-generated" are between AUTO START and 5 // Things that should be "auto-generated" are between AUTO START and
6 // AUTO END (or just AUTO if it's a single line). 6 // AUTO END (or just AUTO if it's a single line).
7 7
8 #library("MintMakerTest"); 8 #library("MintMakerTest");
9 #import("dart:isolate"); 9 #import("dart:isolate");
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 // AUTO 42 // AUTO
43 SendPort port; 43 SendPort port;
44 } 44 }
45 45
46 46
47 // AUTO START 47 // AUTO START
48 class MintWrapper { 48 class MintWrapper {
49 MintWrapper(SendPort this.mint_) {} 49 MintWrapper(SendPort this.mint_) {}
50 50
51 void createPurse(int balance, handlePurse(PurseWrapper purse)) { 51 void createPurse(int balance, handlePurse(PurseWrapper purse)) {
52 mint_.call(balance).receive((var message, SendPort replyTo) { 52 mint_.call(balance).then((var message) {
53 SendPort purse = message[0]; 53 SendPort purse = message[0];
54 handlePurse(new PurseWrapper(purse)); 54 handlePurse(new PurseWrapper(purse));
55 }); 55 });
56 } 56 }
57 57
58 SendPort mint_; 58 SendPort mint_;
59 } 59 }
60 // AUTO END 60 // AUTO END
61 61
62 62
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 // AUTO 130 // AUTO
131 SendPort port; 131 SendPort port;
132 } 132 }
133 133
134 134
135 // AUTO START 135 // AUTO START
136 class PurseWrapper { 136 class PurseWrapper {
137 PurseWrapper(SendPort this.purse_) {} 137 PurseWrapper(SendPort this.purse_) {}
138 138
139 void queryBalance(handleBalance(int balance)) { 139 void queryBalance(handleBalance(int balance)) {
140 purse_.call([ "balance" ]).receive((var message, SendPort replyTo) { 140 purse_.call([ "balance" ]).then((var message) {
141 int balance = message; 141 int balance = message;
142 handleBalance(balance); 142 handleBalance(balance);
143 }); 143 });
144 } 144 }
145 145
146 void sproutPurse(handleSprouted(PurseWrapper sprouted)) { 146 void sproutPurse(handleSprouted(PurseWrapper sprouted)) {
147 purse_.call([ "sprout" ]).receive((var message, SendPort replyTo) { 147 purse_.call([ "sprout" ]).then((var message) {
148 SendPort sprouted = message[0]; 148 SendPort sprouted = message[0];
149 handleSprouted(new PurseWrapper(sprouted)); 149 handleSprouted(new PurseWrapper(sprouted));
150 }); 150 });
151 } 151 }
152 152
153 void deposit(PurseWrapper source, int amount) { 153 void deposit(PurseWrapper source, int amount) {
154 purse_.send([ "deposit", amount, source.purse_ ], null); 154 purse_.send([ "deposit", amount, source.purse_ ], null);
155 } 155 }
156 156
157 157
(...skipping 14 matching lines...) Expand all
172 } 172 }
173 } 173 }
174 174
175 class MintMakerWrapper { 175 class MintMakerWrapper {
176 MintMakerWrapper() { 176 MintMakerWrapper() {
177 port_ = new MintMakerWrapperIsolate().spawn(); 177 port_ = new MintMakerWrapperIsolate().spawn();
178 } 178 }
179 179
180 void makeMint(handleMint(MintWrapper mint)) { 180 void makeMint(handleMint(MintWrapper mint)) {
181 port_.then((SendPort port) { 181 port_.then((SendPort port) {
182 port.call(null).receive((var message, SendPort replyTo) { 182 port.call(null).then((var message) {
183 SendPort mint = message[0]; 183 SendPort mint = message[0];
184 handleMint(new MintWrapper(mint)); 184 handleMint(new MintWrapper(mint));
185 }); 185 });
186 }); 186 });
187 } 187 }
188 188
189 Future<SendPort> port_; 189 Future<SendPort> port_;
190 } 190 }
191 191
192 192
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 Expect.equals(0 + 5 + 42, sprouted.queryBalance()); 266 Expect.equals(0 + 5 + 42, sprouted.queryBalance());
267 Expect.equals(100 - 5 - 42, purse.queryBalance()); 267 Expect.equals(100 - 5 - 42, purse.queryBalance());
268 } 268 }
269 */ 269 */
270 270
271 } 271 }
272 272
273 main() { 273 main() {
274 MintMakerTest.testMain(); 274 MintMakerTest.testMain();
275 } 275 }
OLDNEW
« no previous file with comments | « tests/isolate/src/MessageTest.dart ('k') | tests/isolate/src/Mixed2Test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698