OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #import('../../pkg/unittest/unittest.dart'); | 10 import '../../pkg/unittest/lib/unittest.dart'; |
11 | 11 |
12 class Mint { | 12 class Mint { |
13 Mint() : registry_ = new Map<SendPort, Purse>() { | 13 Mint() : registry_ = new Map<SendPort, Purse>() { |
14 // AUTO START | 14 // AUTO START |
15 ReceivePort mintPort = new ReceivePort(); | 15 ReceivePort mintPort = new ReceivePort(); |
16 port = mintPort.toSendPort(); | 16 port = mintPort.toSendPort(); |
17 serveMint(mintPort); | 17 serveMint(mintPort); |
18 // AUTO END | 18 // AUTO END |
19 } | 19 } |
20 | 20 |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 /* This is an attempt to show how the above code could look like if we had | 215 /* This is an attempt to show how the above code could look like if we had |
216 * better language support for asynchronous messages (deferred/asynccall). | 216 * better language support for asynchronous messages (deferred/asynccall). |
217 * The static helper methods like createPurse and queryBalance would also | 217 * The static helper methods like createPurse and queryBalance would also |
218 * have to be marked async. | 218 * have to be marked async. |
219 | 219 |
220 void run(port) { | 220 void run(port) { |
221 MintMakerWrapper mintMaker = spawnMintMaker(); | 221 MintMakerWrapper mintMaker = spawnMintMaker(); |
222 deferred { | 222 deferred { |
223 MintWrapper mint = asynccall mintMaker.createMint(); | 223 MintWrapper mint = asynccall mintMaker.createMint(); |
224 PurseWrapper purse = asynccall mint.createPurse(100); | 224 PurseWrapper purse = asynccall mint.createPurse(100); |
225 Expect.equals(100, asynccall purse.queryBalance()); | 225 expect(asynccall purse.queryBalance(), 100); |
226 | 226 |
227 PurseWrapper sprouted = asynccall purse.sproutPurse(); | 227 PurseWrapper sprouted = asynccall purse.sproutPurse(); |
228 Expect.equals(0, asynccall sprouted.queryBalance()); | 228 expect(asynccall sprouted.queryBalance(), 0); |
229 | 229 |
230 asynccall sprouted.deposit(purse, 5); | 230 asynccall sprouted.deposit(purse, 5); |
231 Expect.equals(0 + 5, asynccall sprouted.queryBalance()); | 231 expect(asynccall sprouted.queryBalance(), 0 + 5); |
232 Expect.equals(100 - 5, asynccall purse.queryBalance()); | 232 expect(asynccall purse.queryBalance(), 100 - 5); |
233 | 233 |
234 asynccall sprouted.deposit(purse, 42); | 234 asynccall sprouted.deposit(purse, 42); |
235 Expect.equals(0 + 5 + 42, asynccall sprouted.queryBalance()); | 235 expect(asynccall sprouted.queryBalance(), 0 + 5 + 42); |
236 Expect.equals(100 - 5 - 42, asynccall purse.queryBalance()); | 236 expect(asynccall purse.queryBalance(), 100 - 5 - 42); |
237 } | 237 } |
238 } | 238 } |
239 */ | 239 */ |
240 | 240 |
241 /* And a version using futures and wrappers. | 241 /* And a version using futures and wrappers. |
242 | 242 |
243 void run(port) { | 243 void run(port) { |
244 Wrapper<MintMaker> mintMaker = spawnMintMaker(); | 244 Wrapper<MintMaker> mintMaker = spawnMintMaker(); |
245 Future<Mint> mint = mintMaker...createMint(); | 245 Future<Mint> mint = mintMaker...createMint(); |
246 Future<Purse> purse = mint...createPurse(100); | 246 Future<Purse> purse = mint...createPurse(100); |
247 Expect.equals(100, purse.queryBalance()); | 247 expect(purse.queryBalance(), 100); |
248 | 248 |
249 Future<Purse> sprouted = purse...sproutPurse(); | 249 Future<Purse> sprouted = purse...sproutPurse(); |
250 Expect.equals(0, sprouted.queryBalance()); | 250 expect(0, sprouted.queryBalance()); |
251 | 251 |
252 sprouted...deposit(purse, 5); | 252 sprouted...deposit(purse, 5); |
253 Expect.equals(0 + 5, sprouted.queryBalance()); | 253 expect(sprouted.queryBalance(), 0 + 5); |
254 Expect.equals(100 - 5, purse.queryBalance()); | 254 expect(purse.queryBalance(), 100 - 5); |
255 | 255 |
256 sprouted...deposit(purse, 42); | 256 sprouted...deposit(purse, 42); |
257 Expect.equals(0 + 5 + 42, sprouted.queryBalance()); | 257 expect(sprouted.queryBalance(), 0 + 5 + 42); |
258 Expect.equals(100 - 5 - 42, purse.queryBalance()); | 258 expect(purse.queryBalance(), 100 - 5 - 42); |
259 } | 259 } |
260 */ | 260 */ |
261 } | 261 } |
OLD | NEW |