OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 // VMOptions=--enable_async --optimization-counter-threshold=5 |
| 6 |
| 7 import 'package:expect/expect.dart'; |
| 8 |
| 9 import 'dart:async'; |
| 10 |
| 11 // It does not matter where a future is generated. |
| 12 bar(p) async => p; |
| 13 baz(p) => new Future(() => p); |
| 14 |
| 15 foo() async { |
| 16 var b = 0; |
| 17 for(int i = 0; i < 10; i++) { |
| 18 b += (await bar(1)) + (await baz(2)); |
| 19 } |
| 20 return b; |
| 21 } |
| 22 |
| 23 quaz(p) async { |
| 24 var x = 0; |
| 25 try { |
| 26 for (var j = 0; j < 10; j++) { |
| 27 x += await baz(j); |
| 28 } |
| 29 return x; |
| 30 } finally { |
| 31 Expect.equals(x, 45); |
| 32 return p; |
| 33 } |
| 34 } |
| 35 |
| 36 quazz() async { |
| 37 var x = 0; |
| 38 try { |
| 39 try { |
| 40 x = await bar(1); |
| 41 throw x; |
| 42 } catch (e1) { |
| 43 var y = await baz(e1 + 1); |
| 44 throw y; |
| 45 } |
| 46 } catch (e2) { |
| 47 return e2; |
| 48 } |
| 49 } |
| 50 |
| 51 main() async { |
| 52 var result; |
| 53 for (int i = 0; i < 10; i++) { |
| 54 result = await foo(); |
| 55 Expect.equals(result, 30); |
| 56 result = await quaz(17); |
| 57 Expect.equals(result, 17); |
| 58 result = await quazz(); |
| 59 Expect.equals(result, 2); |
| 60 } |
| 61 } |
OLD | NEW |