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

Side by Side Diff: tests/stub-generator/src/MintMakerPromiseWithStubsTest.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=MintMakerPromiseWithStubsTest.dart:Mint,Purse 5 // IsolateStubs=MintMakerPromiseWithStubsTest.dart:Mint,Purse
6 6
7 #import("../../isolate/src/TestFramework.dart"); 7 #import("../../isolate/src/TestFramework.dart");
8 8
9 interface Mint factory MintImpl { 9 interface Mint factory MintImpl {
10 10
11 Mint(); 11 Mint();
12 12
13 Purse createPurse(int balance); 13 Purse createPurse(int balance);
14 14
15 } 15 }
16 16
17 interface Purse factory PurseImpl { 17 interface Purse factory PurseImpl {
18 18
19 Purse(); 19 Purse();
20 20
21 int queryBalance(); 21 int queryBalance();
22 Purse sproutPurse(); 22 Purse sproutPurse();
23 int deposit(int amount, Purse$Proxy source); 23 Promise<int> deposit(int amount, Purse$Proxy source);
24 24
25 } 25 }
26 26
27 class MintImpl implements Mint { 27 class MintImpl implements Mint {
28 28
29 MintImpl() { } 29 MintImpl() { }
30 30
31 Purse createPurse(int balance) { 31 Purse createPurse(int balance) {
32 PurseImpl purse = new PurseImpl(); 32 PurseImpl purse = new PurseImpl();
33 purse.init(this, balance); 33 purse.init(this, balance);
(...skipping 16 matching lines...) Expand all
50 } 50 }
51 51
52 int queryBalance() { 52 int queryBalance() {
53 return _balance; 53 return _balance;
54 } 54 }
55 55
56 Purse sproutPurse() { 56 Purse sproutPurse() {
57 return _mint.createPurse(0); 57 return _mint.createPurse(0);
58 } 58 }
59 59
60 int deposit(int amount, Purse$Proxy proxy) { 60 Promise<int> deposit(int amount, Purse$Proxy proxy) {
61 if (amount < 0) throw "Ha ha"; 61 if (amount < 0) throw "Ha ha";
62 // Because we are in the same isolate as the other purse, we can 62 // Because we are in the same isolate as the other purse, we can
63 // retrieve the proxy's local PurseImpl object and act on it 63 // retrieve the proxy's local PurseImpl object and act on it
64 // directly. Further, a forged purse will not be convertible, and 64 // directly. Further, a forged purse will not be convertible, and
65 // so an attempt to use it will fail. 65 // so an attempt to use it will fail.
66 PurseImpl source = proxy.dynamic.local; 66 Promise<int> balance = new Promise<int>();
67 if (source._balance < amount) throw "Not enough dough."; 67 proxy.addCompleteHandler((_) {
68 _balance += amount; 68 PurseImpl source = proxy.dynamic.local;
69 source._balance -= amount; 69 if (source._balance < amount) throw "Not enough dough.";
70 return _balance; 70 _balance += amount;
71 source._balance -= amount;
72 balance.complete(_balance);
73 });
74 return balance;
71 } 75 }
72 76
73 Mint _mint; 77 Mint _mint;
74 int _balance; 78 int _balance;
75 79
76 } 80 }
77 81
78 class MintMakerPromiseWithStubsTest { 82 class MintMakerPromiseWithStubsTest {
79 83
80 static void testMain(TestExpectation expect) { 84 static void testMain(TestExpectation expect) {
(...skipping 20 matching lines...) Expand all
101 }); 105 });
102 }); 106 });
103 expect.succeeded(); 107 expect.succeeded();
104 } 108 }
105 109
106 } 110 }
107 111
108 main() { 112 main() {
109 runTests([MintMakerPromiseWithStubsTest.testMain]); 113 runTests([MintMakerPromiseWithStubsTest.testMain]);
110 } 114 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698