| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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 // VMOptions=--enable_async --optimization-counter-threshold=5 | 5 // VMOptions=--enable_async --optimization-counter-threshold=5 |
| 6 | 6 |
| 7 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
| 8 | 8 |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 | 10 |
| 11 // It does not matter where a future is generated. | 11 // It does not matter where a future is generated. |
| 12 bar(p) async => p; | 12 bar(p) async => p; |
| 13 baz(p) => new Future(() => p); | 13 baz(p) => new Future(() => p); |
| 14 | 14 |
| 15 foo() async { | 15 foo() async { |
| 16 var b = 0; | 16 var b = 0; |
| 17 for(int i = 0; i < 10; i++) { | 17 for(int i = 0; i < 10; i++) { |
| 18 b += (await bar(1)) + (await baz(2)); | 18 b += (await bar(1)) + (await baz(2)); |
| 19 } | 19 } |
| 20 return b; | 20 return b; |
| 21 } | 21 } |
| 22 | 22 |
| 23 faa() async => (await bar('faa')).length; |
| 24 |
| 23 quaz(p) async { | 25 quaz(p) async { |
| 24 var x = 0; | 26 var x = 0; |
| 25 try { | 27 try { |
| 26 for (var j = 0; j < 10; j++) { | 28 for (var j = 0; j < 10; j++) { |
| 27 x += await baz(j); | 29 x += await baz(j); |
| 28 } | 30 } |
| 29 return x; | 31 return x; |
| 30 } finally { | 32 } finally { |
| 31 Expect.equals(x, 45); | 33 Expect.equals(x, 45); |
| 32 return p; | 34 return p; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 k += c; | 179 k += c; |
| 178 } | 180 } |
| 179 return k; | 181 return k; |
| 180 } | 182 } |
| 181 | 183 |
| 182 main() async { | 184 main() async { |
| 183 var result; | 185 var result; |
| 184 for (int i = 0; i < 10; i++) { | 186 for (int i = 0; i < 10; i++) { |
| 185 result = await foo(); | 187 result = await foo(); |
| 186 Expect.equals(30, result); | 188 Expect.equals(30, result); |
| 189 result = await faa(); |
| 190 Expect.equals(3, result); |
| 187 result = await quaz(17); | 191 result = await quaz(17); |
| 188 Expect.equals(17, result); | 192 Expect.equals(17, result); |
| 189 result = await quazz(); | 193 result = await quazz(); |
| 190 Expect.equals(2, result); | 194 Expect.equals(2, result); |
| 191 result = await nesting(); | 195 result = await nesting(); |
| 192 Expect.equals(5, result); | 196 Expect.equals(5, result); |
| 193 result = await awaitIf(3); | 197 result = await awaitIf(3); |
| 194 Expect.equals("p<5", result); | 198 Expect.equals("p<5", result); |
| 195 result = await awaitIf(5); | 199 result = await awaitIf(5); |
| 196 Expect.equals("p>=5", result); | 200 Expect.equals("p>=5", result); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 215 result = await awaitNestedWhile(4,6); | 219 result = await awaitNestedWhile(4,6); |
| 216 Expect.equals(24, result); | 220 Expect.equals(24, result); |
| 217 result = await awaitAsUnary(bar(1), bar(2)); | 221 result = await awaitAsUnary(bar(1), bar(2)); |
| 218 Expect.equals(3, result); | 222 Expect.equals(3, result); |
| 219 result = await awaitFor(); | 223 result = await awaitFor(); |
| 220 Expect.equals(25, result); | 224 Expect.equals(25, result); |
| 221 result = await awaitForIn(); | 225 result = await awaitForIn(); |
| 222 Expect.equals('abc', result); | 226 Expect.equals('abc', result); |
| 223 } | 227 } |
| 224 } | 228 } |
| OLD | NEW |