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 import "dart:async"; | 5 import "dart:async"; |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 import "package:async_helper/async_helper.dart"; | 7 import "package:async_helper/async_helper.dart"; |
8 | 8 |
9 Stream<int> foo1() async* { | 9 Stream<int> foo1() async* { |
10 yield 1; | 10 yield 1; |
(...skipping 10 matching lines...) Expand all Loading... |
21 i++; | 21 i++; |
22 } | 22 } |
23 } | 23 } |
24 | 24 |
25 Stream<int> foo3(p) async* { | 25 Stream<int> foo3(p) async* { |
26 int i = 0; | 26 int i = 0; |
27 bool t = false; | 27 bool t = false; |
28 yield null; | 28 yield null; |
29 while (true) { | 29 while (true) { |
30 i++; | 30 i++; |
31 a: for (int i = 0; i < p; i++) { | 31 a: |
| 32 for (int i = 0; i < p; i++) { |
32 if (!t) { | 33 if (!t) { |
33 for (int j = 0; j < 3; j++) { | 34 for (int j = 0; j < 3; j++) { |
34 yield -1; | 35 yield -1; |
35 t = true; | 36 t = true; |
36 break a; | 37 break a; |
37 } | 38 } |
38 } | 39 } |
39 await 4; | 40 await 4; |
40 yield i; | 41 yield i; |
41 } | 42 } |
(...skipping 11 matching lines...) Expand all Loading... |
53 } | 54 } |
54 } finally { | 55 } finally { |
55 // Canceling the stream-subscription should run the finalizer. | 56 // Canceling the stream-subscription should run the finalizer. |
56 finalized.complete(true); | 57 finalized.complete(true); |
57 } | 58 } |
58 } | 59 } |
59 | 60 |
60 test() async { | 61 test() async { |
61 Expect.listEquals([1, 20], await (foo1().toList())); | 62 Expect.listEquals([1, 20], await (foo1().toList())); |
62 Expect.listEquals([0, 1, 2, 3], await (foo2().take(4).toList())); | 63 Expect.listEquals([0, 1, 2, 3], await (foo2().take(4).toList())); |
63 Expect.listEquals([null, -1, 0, 1, 2, 3, 0, 1, 2, 3], | 64 Expect.listEquals( |
64 await (foo3(4).take(10).toList())); | 65 [null, -1, 0, 1, 2, 3, 0, 1, 2, 3], await (foo3(4).take(10).toList())); |
65 Expect.listEquals([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], | 66 Expect.listEquals( |
66 await (foo4().take(10).toList())); | 67 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], await (foo4().take(10).toList())); |
67 Expect.isTrue(await (finalized.future)); | 68 Expect.isTrue(await (finalized.future)); |
68 } | 69 } |
69 | 70 |
70 main () { | 71 main() { |
71 asyncStart(); | 72 asyncStart(); |
72 test().then((_) { | 73 test().then((_) { |
73 asyncEnd(); | 74 asyncEnd(); |
74 }); | 75 }); |
75 } | 76 } |
OLD | NEW |