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 main() async { |
| 37 var result; |
| 38 for (int i = 0; i < 10; i++) { |
| 39 result = await foo(); |
| 40 Expect.equals(result, 30); |
| 41 } |
| 42 result = await quaz(17); |
| 43 Expect.equals(result, 17); |
| 44 } |
OLD | NEW |