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:sequence_zip/stream_zip.dart"; | 6 import "package:sequence_zip/stream_zip.dart"; |
7 import "package:unittest/unittest.dart"; | 7 import "package:unittest/unittest.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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 [streamError(mks([1, 2, 3, 4]), 4), | 134 [streamError(mks([1, 2, 3, 4]), 4), |
135 (new StreamController()..add(4)..add(5)..add(6)).stream, | 135 (new StreamController()..add(4)..add(5)..add(6)).stream, |
136 (new StreamController()..add(7)..add(8)..add(9)).stream] | 136 (new StreamController()..add(7)..add(8)..add(9)).stream] |
137 ).toList(), | 137 ).toList(), |
138 throwsA(equals("BAD"))); | 138 throwsA(equals("BAD"))); |
139 }); | 139 }); |
140 | 140 |
141 test("Error after first end", () { | 141 test("Error after first end", () { |
142 StreamController controller = new StreamController(); | 142 StreamController controller = new StreamController(); |
143 controller..add(7)..add(8)..add(9); | 143 controller..add(7)..add(8)..add(9); |
144 testZip([mks([1, 2, 3]), | 144 int ctr = 2; |
145 mks([4, 5, 6]), | 145 Function addErrorIf(x) { |
| 146 return (y) { |
| 147 // Adds error to controller after both of the first two streams have |
| 148 // provided all three elements. |
| 149 if (x == y && --ctr == 0) Timer.run(() { controller.addError("BAD"); }); |
| 150 return y; |
| 151 }; |
| 152 } |
| 153 testZip([mks([1, 2, 3].map(addErrorIf(3))), |
| 154 mks([4, 5, 6].map(addErrorIf(6))), |
146 controller.stream], | 155 controller.stream], |
147 [[1, 4, 7], [2, 5, 8], [3, 6, 9]]); | 156 [[1, 4, 7], [2, 5, 8], [3, 6, 9]]); |
148 // This comes after the first three events in all cases, since they | |
149 // use durations no greater than 10 ms. | |
150 new Timer(const Duration(milliseconds: 100), () { | |
151 controller.addError("BAD"); | |
152 }); | |
153 }); | 157 }); |
154 | 158 |
155 test("Pause/Resume", () { | 159 test("Pause/Resume", () { |
156 var done = expectAsync0((){}); // Call to complete test. | 160 var done = expectAsync0((){}); // Call to complete test. |
157 | 161 |
158 int sc1p = 0; | 162 int sc1p = 0; |
159 StreamController c1 = new StreamController( | 163 StreamController c1 = new StreamController( |
160 onPause: () { | 164 onPause: () { |
161 sc1p++; | 165 sc1p++; |
162 }, | 166 }, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 } else if (ctr == 2) { | 224 } else if (ctr == 2) { |
221 sub.pause(); | 225 sub.pause(); |
222 new Future.delayed(const Duration(milliseconds: 25)).then((_) { | 226 new Future.delayed(const Duration(milliseconds: 25)).then((_) { |
223 sub.resume(); | 227 sub.resume(); |
224 }); | 228 }); |
225 } | 229 } |
226 ctr++; | 230 ctr++; |
227 }, count: 4)); | 231 }, count: 4)); |
228 }); | 232 }); |
229 } | 233 } |
OLD | NEW |