OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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:async/stream_zip.dart"; | 6 import "package:async/stream_zip.dart"; |
7 import "package:test/test.dart"; | 7 import "package:test/test.dart"; |
8 | 8 |
9 /// Create an error with the same values as [base], except that it throwsA | 9 /// Create an error with the same values as [base], except that it throwsA |
10 /// when seeing the value [errorValue]. | 10 /// when seeing the value [errorValue]. |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 Timer.run(() { controller.addError("BAD-6"); }); | 148 Timer.run(() { controller.addError("BAD-6"); }); |
149 s.close(); | 149 s.close(); |
150 }); | 150 }); |
151 testZip([mks([1, 2, 3]).transform(trans), | 151 testZip([mks([1, 2, 3]).transform(trans), |
152 mks([4, 5, 6]).transform(trans), | 152 mks([4, 5, 6]).transform(trans), |
153 controller.stream], | 153 controller.stream], |
154 [[1, 4, 7], [2, 5, 8], [3, 6, 9]]); | 154 [[1, 4, 7], [2, 5, 8], [3, 6, 9]]); |
155 }); | 155 }); |
156 | 156 |
157 test("Pause/Resume", () { | 157 test("Pause/Resume", () { |
158 var done = expectAsync((){}); // Call to complete test. | |
159 | |
160 int sc1p = 0; | 158 int sc1p = 0; |
161 StreamController c1 = new StreamController( | 159 StreamController c1 = new StreamController( |
162 onPause: () { | 160 onPause: () { |
163 sc1p++; | 161 sc1p++; |
164 }, | 162 }, |
165 onResume: () { | 163 onResume: () { |
166 sc1p--; | 164 sc1p--; |
167 }); | 165 }); |
168 | 166 |
169 int sc2p = 0; | 167 int sc2p = 0; |
170 StreamController c2 = new StreamController( | 168 StreamController c2 = new StreamController( |
171 onPause: () { | 169 onPause: () { |
172 sc2p++; | 170 sc2p++; |
173 }, | 171 }, |
174 onResume: () { | 172 onResume: () { |
175 sc2p--; | 173 sc2p--; |
176 }); | 174 }); |
175 | |
176 var done = expectAsync((){ | |
177 expect(sc1p, equals(1)); | |
178 expect(sc2p, equals(0)); | |
179 }); // Call to complete test. | |
nweiz
2015/07/01 00:47:24
Why are these expects added?
| |
180 | |
177 Stream zip = new StreamZip([c1.stream, c2.stream]); | 181 Stream zip = new StreamZip([c1.stream, c2.stream]); |
178 | 182 |
179 const ms25 = const Duration(milliseconds: 25); | 183 const ms25 = const Duration(milliseconds: 25); |
180 | 184 |
181 // StreamIterator uses pause and resume to control flow. | 185 // StreamIterator uses pause and resume to control flow. |
182 StreamIterator it = new StreamIterator(zip); | 186 StreamIterator it = new StreamIterator(zip); |
183 | 187 |
184 it.moveNext().then((hasMore) { | 188 it.moveNext().then((hasMore) { |
185 expect(hasMore, isTrue); | 189 expect(hasMore, isTrue); |
186 expect(it.current, equals([1, 2])); | 190 expect(it.current, equals([1, 2])); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 } else if (ctr == 2) { | 226 } else if (ctr == 2) { |
223 sub.pause(); | 227 sub.pause(); |
224 new Future.delayed(const Duration(milliseconds: 25)).then((_) { | 228 new Future.delayed(const Duration(milliseconds: 25)).then((_) { |
225 sub.resume(); | 229 sub.resume(); |
226 }); | 230 }); |
227 } | 231 } |
228 ctr++; | 232 ctr++; |
229 }, count: 4)); | 233 }, count: 4)); |
230 }); | 234 }); |
231 } | 235 } |
OLD | NEW |