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

Side by Side Diff: tests/stub-generator/src/MintMakerFullyIsolatedTest-generatedTest.dart

Issue 8403040: Don't wait unnecessarily. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 1 month 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
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 // IsolateStubs=MintMakerFullyIsolatedTest.dart:Mint,Purse,PowerfulPurse 5 // IsolateStubs=MintMakerFullyIsolatedTest.dart:Mint,Purse,PowerfulPurse
6 6
7 #import("../../isolate/src/TestFramework.dart"); 7 #import("../../isolate/src/TestFramework.dart");
8 8
9 /* class = Purse (tests/stub-generator/src/MintMakerFullyIsolatedTest.dart/MintM akerFullyIsolatedTest.dart: 9) */ 9 /* class = Purse (tests/stub-generator/src/MintMakerFullyIsolatedTest.dart/MintM akerFullyIsolatedTest.dart: 9) */
10 10
11 interface Purse$Proxy { 11 interface Purse$Proxy extends Proxy {
12 Promise<int> queryBalance(); 12 Promise<int> queryBalance();
13 13
14 Purse$Proxy sproutPurse(); 14 Purse$Proxy sproutPurse();
15 15
16 Promise<int> deposit(int amount, Purse$Proxy source); 16 Promise<int> deposit(int amount, Purse$Proxy source);
17 } 17 }
18 18
19 class Purse$ProxyImpl extends ProxyImpl implements Purse$Proxy { 19 class Purse$ProxyImpl extends ProxyImpl implements Purse$Proxy {
20 Purse$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { } 20 Purse$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { }
21 Purse$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.call([null] )) { } 21 Purse$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.call([null] )) { }
(...skipping 27 matching lines...) Expand all
49 } else if (command == "queryBalance") { 49 } else if (command == "queryBalance") {
50 int queryBalance = target.queryBalance(); 50 int queryBalance = target.queryBalance();
51 reply(queryBalance); 51 reply(queryBalance);
52 } else if (command == "sproutPurse") { 52 } else if (command == "sproutPurse") {
53 Purse$Proxy sproutPurse = target.sproutPurse(); 53 Purse$Proxy sproutPurse = target.sproutPurse();
54 reply(sproutPurse); 54 reply(sproutPurse);
55 } else if (command == "deposit") { 55 } else if (command == "deposit") {
56 int amount = message[1]; 56 int amount = message[1];
57 List<Promise<SendPort>> promises = new List<Promise<SendPort>>(); 57 List<Promise<SendPort>> promises = new List<Promise<SendPort>>();
58 promises.add(new PromiseProxy<SendPort>(new Promise<SendPort>.fromValue(me ssage[2]))); 58 promises.add(new PromiseProxy<SendPort>(new Promise<SendPort>.fromValue(me ssage[2])));
59 Promise done = new Promise(); 59 Purse$Proxy source = new Purse$ProxyImpl(promises[0]);
60 done.waitFor(promises, 1); 60 Promise<int> deposit = target.deposit(amount, source);
61 done.addCompleteHandler((_) { 61 reply(deposit);
62 Purse$Proxy source = new Purse$ProxyImpl(promises[0]);
63 Promise<int> deposit = target.deposit(amount, source);
64 reply(deposit);
65 });
66 } else { 62 } else {
67 // TODO(kasperl,benl): Somehow throw an exception instead. 63 // TODO(kasperl,benl): Somehow throw an exception instead.
68 reply("Exception: command '" + command + "' not understood by Purse."); 64 reply("Exception: command '" + command + "' not understood by Purse.");
69 } 65 }
70 } 66 }
71 } 67 }
72 68
73 class Purse$Dispatcher$Isolate extends Isolate { 69 class Purse$Dispatcher$Isolate extends Isolate {
74 Purse$Dispatcher$Isolate() : super() { } 70 Purse$Dispatcher$Isolate() : super() { }
75 71
76 void main() { 72 void main() {
77 this.port.receive(void _(var message, SendPort replyTo) { 73 this.port.receive(void _(var message, SendPort replyTo) {
78 Purse thing = new Purse(); 74 Purse thing = new Purse();
79 SendPort port = Dispatcher.serve(new Purse$Dispatcher(thing)); 75 SendPort port = Dispatcher.serve(new Purse$Dispatcher(thing));
80 Proxy proxy = new Proxy.forPort(replyTo); 76 Proxy proxy = new Proxy.forPort(replyTo);
81 proxy.send([port]); 77 proxy.send([port]);
82 }); 78 });
83 } 79 }
84 } 80 }
85 81
86 /* class = PowerfulPurse (tests/stub-generator/src/MintMakerFullyIsolatedTest.da rt/MintMakerFullyIsolatedTest.dart: 18) */ 82 /* class = PowerfulPurse (tests/stub-generator/src/MintMakerFullyIsolatedTest.da rt/MintMakerFullyIsolatedTest.dart: 18) */
87 83
88 interface PowerfulPurse$Proxy { 84 interface PowerfulPurse$Proxy extends Proxy {
89 void init(Mint$Proxy mint, int balance); 85 void init(Mint$Proxy mint, int balance);
90 86
91 Promise<int> grab(int amount); 87 Promise<int> grab(int amount);
92 88
93 Purse$Proxy weak(); 89 Purse$Proxy weak();
94 } 90 }
95 91
96 class PowerfulPurse$ProxyImpl extends ProxyImpl implements PowerfulPurse$Proxy { 92 class PowerfulPurse$ProxyImpl extends ProxyImpl implements PowerfulPurse$Proxy {
97 PowerfulPurse$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { } 93 PowerfulPurse$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { }
98 PowerfulPurse$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.cal l([null])) { } 94 PowerfulPurse$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.cal l([null])) { }
(...skipping 21 matching lines...) Expand all
120 class PowerfulPurse$Dispatcher extends Dispatcher<PowerfulPurse> { 116 class PowerfulPurse$Dispatcher extends Dispatcher<PowerfulPurse> {
121 PowerfulPurse$Dispatcher(PowerfulPurse thing) : super(thing) { } 117 PowerfulPurse$Dispatcher(PowerfulPurse thing) : super(thing) { }
122 118
123 void process(var message, void reply(var response)) { 119 void process(var message, void reply(var response)) {
124 String command = message[0]; 120 String command = message[0];
125 if (command == "PowerfulPurse") { 121 if (command == "PowerfulPurse") {
126 } else if (command == "init") { 122 } else if (command == "init") {
127 List<Promise<SendPort>> promises = new List<Promise<SendPort>>(); 123 List<Promise<SendPort>> promises = new List<Promise<SendPort>>();
128 promises.add(new PromiseProxy<SendPort>(new Promise<SendPort>.fromValue(me ssage[1]))); 124 promises.add(new PromiseProxy<SendPort>(new Promise<SendPort>.fromValue(me ssage[1])));
129 int balance = message[2]; 125 int balance = message[2];
130 Promise done = new Promise(); 126 Mint$Proxy mint = new Mint$ProxyImpl(promises[0]);
131 done.waitFor(promises, 1); 127 target.init(mint, balance);
132 done.addCompleteHandler((_) {
133 Mint$Proxy mint = new Mint$ProxyImpl(promises[0]);
134 target.init(mint, balance);
135 });
136 } else if (command == "grab") { 128 } else if (command == "grab") {
137 int amount = message[1]; 129 int amount = message[1];
138 int grab = target.grab(amount); 130 int grab = target.grab(amount);
139 reply(grab); 131 reply(grab);
140 } else if (command == "weak") { 132 } else if (command == "weak") {
141 Purse weak = target.weak(); 133 Purse weak = target.weak();
142 SendPort port = Dispatcher.serve(new Purse$Dispatcher(weak)); 134 SendPort port = Dispatcher.serve(new Purse$Dispatcher(weak));
143 reply(port); 135 reply(port);
144 } else { 136 } else {
145 // TODO(kasperl,benl): Somehow throw an exception instead. 137 // TODO(kasperl,benl): Somehow throw an exception instead.
(...skipping 10 matching lines...) Expand all
156 PowerfulPurse thing = new PowerfulPurse(); 148 PowerfulPurse thing = new PowerfulPurse();
157 SendPort port = Dispatcher.serve(new PowerfulPurse$Dispatcher(thing)); 149 SendPort port = Dispatcher.serve(new PowerfulPurse$Dispatcher(thing));
158 Proxy proxy = new Proxy.forPort(replyTo); 150 Proxy proxy = new Proxy.forPort(replyTo);
159 proxy.send([port]); 151 proxy.send([port]);
160 }); 152 });
161 } 153 }
162 } 154 }
163 155
164 /* class = Mint (tests/stub-generator/src/MintMakerFullyIsolatedTest.dart/MintMa kerFullyIsolatedTest.dart: 28) */ 156 /* class = Mint (tests/stub-generator/src/MintMakerFullyIsolatedTest.dart/MintMa kerFullyIsolatedTest.dart: 28) */
165 157
166 interface Mint$Proxy { 158 interface Mint$Proxy extends Proxy {
167 Purse$Proxy createPurse(int balance); 159 Purse$Proxy createPurse(int balance);
168 160
169 PowerfulPurse$Proxy promote(Purse$Proxy purse); 161 Promise<PowerfulPurse$Proxy> promote(Purse$Proxy purse);
170 } 162 }
171 163
172 class Mint$ProxyImpl extends ProxyImpl implements Mint$Proxy { 164 class Mint$ProxyImpl extends ProxyImpl implements Mint$Proxy {
173 Mint$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { } 165 Mint$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { }
174 Mint$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.call([null]) ) { } 166 Mint$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.call([null]) ) { }
175 factory Mint$ProxyImpl.createIsolate() { 167 factory Mint$ProxyImpl.createIsolate() {
176 Proxy isolate = new Proxy.forIsolate(new Mint$Dispatcher$Isolate()); 168 Proxy isolate = new Proxy.forIsolate(new Mint$Dispatcher$Isolate());
177 return new Mint$ProxyImpl.forIsolate(isolate); 169 return new Mint$ProxyImpl.forIsolate(isolate);
178 } 170 }
179 factory Mint$ProxyImpl.localProxy(Mint obj) { 171 factory Mint$ProxyImpl.localProxy(Mint obj) {
180 return new Mint$ProxyImpl(new Promise<SendPort>.fromValue(Dispatcher.serve(n ew Mint$Dispatcher(obj)))); 172 return new Mint$ProxyImpl(new Promise<SendPort>.fromValue(Dispatcher.serve(n ew Mint$Dispatcher(obj))));
181 } 173 }
182 174
183 Purse$Proxy createPurse(int balance) { 175 Purse$Proxy createPurse(int balance) {
184 return new Purse$ProxyImpl(new PromiseProxy<SendPort>(this.call(["createPurs e", balance]))); 176 return new Purse$ProxyImpl(new PromiseProxy<SendPort>(this.call(["createPurs e", balance])));
185 } 177 }
186 178
187 PowerfulPurse$Proxy promote(Purse$Proxy purse) { 179 Promise<PowerfulPurse$Proxy> promote(Purse$Proxy purse) {
188 return new PowerfulPurse$ProxyImpl(new PromiseProxy<SendPort>(this.call(["pr omote", purse]))); 180 return new PromiseProxy<PowerfulPurse$Proxy>(this.call(["promote", purse]));
189 } 181 }
190 } 182 }
191 183
192 class Mint$Dispatcher extends Dispatcher<Mint> { 184 class Mint$Dispatcher extends Dispatcher<Mint> {
193 Mint$Dispatcher(Mint thing) : super(thing) { } 185 Mint$Dispatcher(Mint thing) : super(thing) { }
194 186
195 void process(var message, void reply(var response)) { 187 void process(var message, void reply(var response)) {
196 String command = message[0]; 188 String command = message[0];
197 if (command == "Mint") { 189 if (command == "Mint") {
198 } else if (command == "createPurse") { 190 } else if (command == "createPurse") {
199 int balance = message[1]; 191 int balance = message[1];
200 Purse$Proxy createPurse = target.createPurse(balance); 192 Purse$Proxy createPurse = target.createPurse(balance);
201 reply(createPurse); 193 reply(createPurse);
202 } else if (command == "promote") { 194 } else if (command == "promote") {
203 List<Promise<SendPort>> promises = new List<Promise<SendPort>>(); 195 List<Promise<SendPort>> promises = new List<Promise<SendPort>>();
204 promises.add(new PromiseProxy<SendPort>(new Promise<SendPort>.fromValue(me ssage[1]))); 196 promises.add(new PromiseProxy<SendPort>(new Promise<SendPort>.fromValue(me ssage[1])));
205 Promise done = new Promise(); 197 Purse$Proxy purse = new Purse$ProxyImpl(promises[0]);
206 done.waitFor(promises, 1); 198 Promise<PowerfulPurse$Proxy> promote = target.promote(purse);
207 done.addCompleteHandler((_) { 199 reply(promote);
208 Purse$Proxy purse = new Purse$ProxyImpl(promises[0]);
209 PowerfulPurse$Proxy promote = target.promote(purse);
210 reply(promote);
211 });
212 } else { 200 } else {
213 // TODO(kasperl,benl): Somehow throw an exception instead. 201 // TODO(kasperl,benl): Somehow throw an exception instead.
214 reply("Exception: command '" + command + "' not understood by Mint."); 202 reply("Exception: command '" + command + "' not understood by Mint.");
215 } 203 }
216 } 204 }
217 } 205 }
218 206
219 class Mint$Dispatcher$Isolate extends Isolate { 207 class Mint$Dispatcher$Isolate extends Isolate {
220 Mint$Dispatcher$Isolate() : super() { } 208 Mint$Dispatcher$Isolate() : super() { }
221 209
(...skipping 22 matching lines...) Expand all
244 // Return an int so we can wait for it to complete. Shame we can't 232 // Return an int so we can wait for it to complete. Shame we can't
245 // have a Promise<void>. 233 // have a Promise<void>.
246 int grab(int amount); 234 int grab(int amount);
247 Purse weak(); 235 Purse weak();
248 } 236 }
249 237
250 interface Mint factory MintImpl { 238 interface Mint factory MintImpl {
251 Mint(); 239 Mint();
252 240
253 Purse$Proxy createPurse(int balance); 241 Purse$Proxy createPurse(int balance);
254 PowerfulPurse$Proxy promote(Purse$Proxy purse); 242 Promise<PowerfulPurse$Proxy> promote(Purse$Proxy purse);
255 } 243 }
256 244
257 // Because promises can't be used as keys in maps until they have 245 // Because promises can't be used as keys in maps until they have
258 // completed, provide a wrapper. Note that if any key promise fails to 246 // completed, provide a wrapper. Note that if any key promise fails to
259 // resolve, then get()'s return may also fail to resolve. Also, 247 // resolve, then get()'s return may also fail to resolve. Also,
260 // although the logic is fine, this can't be used for a 248 // although the logic is fine, this can't be used for a
261 // ProxyMap. Perhaps both Proxy and Promise should inherit from 249 // ProxyMap. Perhaps both Proxy and Promise should inherit from
262 // Completable? 250 // Completable? Also, not sure if implementing Collection is really
263 // NB: not tested and known to be buggy. Will fix in a future change. 251 // sustainable, we shall see.
264 class PromiseMap<S extends Promise, T> { 252 class ProxySet<T extends Proxy> implements Collection<T> {
floitsch 2011/10/27 16:16:54 why not Set<T> ?
Ben Laurie (Google) 2011/10/27 16:34:57 Lazy :-) I will fix.
265 253
266 PromiseMap() { 254 ProxySet() {
255 _set = new List<T>();
256 }
257
258 ProxySet.fromList(this._set);
259
260 void add (T t) {
floitsch 2011/10/27 16:16:54 remove space.
261 for (T x in _set)
floitsch 2011/10/27 16:16:54 use {}
Ben Laurie (Google) 2011/10/27 16:34:57 Sigh.
262 if (x === t)
263 return;
floitsch 2011/10/27 16:16:54 either put "return" on the same line, or put {} ar
Ben Laurie (Google) 2011/10/27 16:34:57 Really? Is that official? I _hate_ that style (bot
264 if (t.hasValue())
floitsch 2011/10/27 16:16:54 {}
265 for (T x in _set)
floitsch 2011/10/27 16:16:54 {}
266 if (x.hasValue() && x == t)
floitsch 2011/10/27 16:16:54 {} or same line.
267 return;
268 _set.add(t);
269 t.addCompleteHandler((_) {
270 _remove(t, 1);
271 });
272 }
273
274 void _remove(T t, int threshold) {
275 int count = 0;
276 for (int n = 0; n < _set.length; ++n)
floitsch 2011/10/27 16:16:54 {}
277 if (_set[n].hasValue() && _set[n] == t)
floitsch 2011/10/27 16:16:54 {}
278 if (++count > threshold) {
279 _set.removeRange(n, 1);
280 --n;
281 }
282 }
283
284 void remove(T t) {
285 t.addCompleteHandler((_) {
286 _remove(t, 0);
287 });
288 }
289
290 int get length() => _set.length;
291 void forEach(void f(T element)) { _set.forEach(f); }
292 ProxySet<T> filter(bool f(T element))
floitsch 2011/10/27 16:16:54 convention is that => is only allowed on the same
Ben Laurie (Google) 2011/10/27 16:34:57 Done.
293 => new ProxySet<T>.fromList(_set.filter(f));
294 bool every(bool f(T element)) => _set.every(f);
295 bool some(bool f(T element)) => _set.some(f);
296 bool isEmpty() => _set.isEmpty();
297 Iterator<T> iterator() => _set.iterator();
298
299 List<T> _set;
300
301 }
302
303
304 class ProxyMap<S extends Proxy, T> {
305
306 ProxyMap() {
267 _map = new Map<S, T>(); 307 _map = new Map<S, T>();
268 _incomplete = new Set<S>(); 308 _incomplete = new ProxySet<S>();
269 } 309 }
270 310
271 T add(S s, T t) { 311 T add(S s, T t) {
272 _incomplete.add(s); 312 _incomplete.add(s);
273 s.addCompleteHandler((_) { 313 s.addCompleteHandler((_) {
274 _map[s] = t; 314 _map[s] = t;
275 _incomplete.remove(s); 315 _incomplete.remove(s);
276 }); 316 });
277 return t; 317 return t;
278 } 318 }
279 319
280 Promise<T> find(S s) { 320 Promise<T> find(S s) {
281 T t = _map[s]; 321 // premature optimisation?
282 if (t != null) 322 if (s.hasValue()) {
283 return new Promise<T>.fromValue(t); 323 T t = _map[s];
324 if (t != null)
floitsch 2011/10/27 16:16:54 {} or same line.
floitsch 2011/10/27 16:16:54 t !== null
Ben Laurie (Google) 2011/10/27 16:34:57 Really? I've been explcitly told === is not needed
325 return new Promise<T>.fromValue(t);
326 }
284 Promise<T> p = new Promise<T>(); 327 Promise<T> p = new Promise<T>();
285 int counter = _incomplete.length; 328 int counter = _incomplete.length;
286 p.join(_incomplete, bool (S completed) { 329 p.join(_incomplete, bool (S completed) {
287 if (completed != s) { 330 if (completed != s) {
288 if (--counter == 0) { 331 if (--counter == 0) {
289 p.complete(null); 332 p.complete(null);
290 return true; 333 return true;
291 } 334 }
292 return false; 335 return false;
293 } 336 }
294 p.complete(_map[s]); 337 p.complete(_map[s]);
295 return true; 338 return true;
296 }); 339 });
297 return p; 340 return p;
298 } 341 }
299 342
300 Set<S> _incomplete; 343 ProxySet<S> _incomplete;
301 Map<S, T> _map; 344 Map<S, T> _map;
302 345
303 } 346 }
304 347
348
305 class MintImpl implements Mint { 349 class MintImpl implements Mint {
306 350
307 MintImpl() { 351 MintImpl() {
308 //print('mint'); 352 //print('mint');
309 if (_power == null) 353 if (_power == null)
310 _power = new Map<Purse$Proxy, PowerfulPurse$Proxy>(); 354 _power = new ProxyMap<Purse$Proxy, PowerfulPurse$Proxy>();
311 } 355 }
312 356
313 Purse$Proxy createPurse(int balance) { 357 Purse$Proxy createPurse(int balance) {
314 //print('createPurse'); 358 //print('createPurse');
315 PowerfulPurse$ProxyImpl purse = 359 PowerfulPurse$ProxyImpl purse =
316 new PowerfulPurse$ProxyImpl.createIsolate(); 360 new PowerfulPurse$ProxyImpl.createIsolate();
317 Mint$Proxy thisProxy = new Mint$ProxyImpl.localProxy(this); 361 Mint$Proxy thisProxy = new Mint$ProxyImpl.localProxy(this);
318 purse.init(thisProxy, balance); 362 purse.init(thisProxy, balance);
319 363
320 Purse$Proxy weakPurse = purse.weak(); 364 Purse$Proxy weakPurse = purse.weak();
321 weakPurse.addCompleteHandler(() { 365 weakPurse.addCompleteHandler((_) {
322 //print('cP1'); 366 //print('cP1');
323 _power[weakPurse] = purse; 367 _power.add(weakPurse, purse);
324 //print('cP2'); 368 //print('cP2');
325 }); 369 });
326 return weakPurse; 370 return weakPurse;
327 } 371 }
328 372
329 PowerfulPurse$Proxy promote(Purse$Proxy purse) { 373 Promise<PowerfulPurse$Proxy> promote(Purse$Proxy purse) {
330 // FIXME(benl): we should be using a PromiseMap here. But we get 374 // FIXME(benl): we should be using a PromiseMap here. But we get
331 // away with it in this test for now. 375 // away with it in this test for now.
332 //print('promote $purse/${_power[purse]}'); 376 //print('promote $purse/${_power[purse]}');
333 return _power[purse]; 377 return _power.find(purse);
334 } 378 }
335 379
336 static Map<Purse$Proxy, PowerfulPurse$Proxy> _power; 380 static ProxyMap<Purse$Proxy, PowerfulPurse$Proxy> _power;
337 } 381 }
338 382
339 class PurseImpl implements PowerfulPurse { 383 class PurseImpl implements PowerfulPurse {
340 384
341 // FIXME(benl): autogenerate constructor, get rid of init(...). 385 // FIXME(benl): autogenerate constructor, get rid of init(...).
342 // Note that this constructor should not exist in the public interface 386 // Note that this constructor should not exist in the public interface
343 // PurseImpl(this._mint, this._balance) { } 387 // PurseImpl(this._mint, this._balance) { }
344 PurseImpl() { } 388 PurseImpl() { }
345 389
346 init(Mint$Proxy mint, int balance) { 390 init(Mint$Proxy mint, int balance) {
347 this._mint = mint; 391 this._mint = mint;
348 this._balance = balance; 392 this._balance = balance;
349 } 393 }
350 394
351 int queryBalance() { 395 int queryBalance() {
352 return _balance; 396 return _balance;
353 } 397 }
354 398
355 Purse$Proxy sproutPurse() { 399 Purse$Proxy sproutPurse() {
356 //print('sprout'); 400 //print('sprout');
357 return _mint.createPurse(0); 401 return _mint.createPurse(0);
358 } 402 }
359 403
360 Promise<int> deposit(int amount, Purse$Proxy proxy) { 404 Promise<int> deposit(int amount, Purse$Proxy proxy) {
361 //print('deposit'); 405 //print('deposit');
362 Promise<int> grabbed = _mint.promote(proxy).grab(amount); 406 Promise<PowerfulPurse$Proxy> powerful = _mint.promote(proxy);
363 Promise<int> done = new Promise<int>(); 407
364 grabbed.then((int) { 408 return powerful.then(() {
365 //print("deposit done"); 409 powerful.value.grab(amount);
410 return amount;
411 }).then((int amount) {
366 _balance += amount; 412 _balance += amount;
367 done.complete(_balance); 413 return _balance;
368 }); 414 });
369 return done;
370 } 415 }
371 416
372 int grab(int amount) { 417 int grab(int amount) {
373 //print("grab"); 418 //print("grab");
374 if (_balance < amount) throw "Not enough dough."; 419 if (_balance < amount) throw "Not enough dough.";
375 _balance -= amount; 420 _balance -= amount;
376 return amount; 421 return amount;
377 } 422 }
378 423
379 Purse weak() { 424 Purse weak() {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 Promise<int> allDone = new Promise<int>(); 468 Promise<int> allDone = new Promise<int>();
424 allDone.waitFor([d3, inner, inner2], 3); 469 allDone.waitFor([d3, inner, inner2], 3);
425 allDone.then((_) => expect.succeeded()); 470 allDone.then((_) => expect.succeeded());
426 } 471 }
427 472
428 } 473 }
429 474
430 main() { 475 main() {
431 runTests([MintMakerFullyIsolatedTest.testMain]); 476 runTests([MintMakerFullyIsolatedTest.testMain]);
432 } 477 }
OLDNEW
« no previous file with comments | « tests/stub-generator/src/MintMakerFullyIsolatedTest.dart ('k') | tests/stub-generator/src/MintMakerPromiseWithStubsTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698