OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 // This test may crash dart2js. | 5 // This test may crash dart2js. |
6 | 6 |
7 import "dart:async"; | 7 import "dart:async"; |
8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
9 import "package:async_helper/async_helper.dart"; | 9 import "package:async_helper/async_helper.dart"; |
10 | 10 |
11 main() { | 11 main() { |
12 var res = []; | 12 var res = []; |
13 fisk() async* { | 13 fisk() async* { |
14 res.add("+fisk"); | 14 res.add("+fisk"); |
15 try { | 15 try { |
16 for (int i = 0; i < 2; i++) { | 16 for (int i = 0; i < 2; i++) { |
17 yield await new Future.microtask(() => i); | 17 yield await new Future.microtask(() => i); |
18 } | 18 } |
19 } finally { | 19 } finally { |
20 res.add("-fisk"); | 20 res.add("-fisk"); |
21 } | 21 } |
22 } | 22 } |
23 | 23 |
24 fugl(int count) async { | 24 fugl(int count) async { |
25 res.add("fisk $count"); | 25 res.add("fisk $count"); |
26 try { | 26 try { |
27 await for(int i in fisk().take(count)) res.add(i); | 27 await for (int i in fisk().take(count)) res.add(i); |
28 } finally { | 28 } finally { |
29 res.add("done"); | 29 res.add("done"); |
30 } | 30 } |
31 } | 31 } |
32 | 32 |
33 asyncStart(); | 33 asyncStart(); |
34 fugl(3).whenComplete(() => fugl(2)) | 34 fugl(3) |
| 35 .whenComplete(() => fugl(2)) |
35 .whenComplete(() => fugl(1)) | 36 .whenComplete(() => fugl(1)) |
36 .whenComplete(() { | 37 .whenComplete(() { |
37 Expect.listEquals( | 38 Expect.listEquals([ |
38 ["fisk 3", "+fisk", 0, 1, "-fisk", "done", | 39 "fisk 3", |
39 "fisk 2", "+fisk", 0, 1, "-fisk", "done", | 40 "+fisk", |
40 "fisk 1", "+fisk", 0, "-fisk", "done"], | 41 0, |
41 res); | 42 1, |
| 43 "-fisk", |
| 44 "done", |
| 45 "fisk 2", |
| 46 "+fisk", |
| 47 0, |
| 48 1, |
| 49 "-fisk", |
| 50 "done", |
| 51 "fisk 1", |
| 52 "+fisk", |
| 53 0, |
| 54 "-fisk", |
| 55 "done" |
| 56 ], res); |
42 asyncEnd(); | 57 asyncEnd(); |
43 }); | 58 }); |
44 } | 59 } |
OLD | NEW |