| 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 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 class Trace { | 9 class Trace { |
| 10 String trace; | 10 String trace; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 Stream timedCounter(int maxCount) { | 141 Stream timedCounter(int maxCount) { |
| 142 StreamController controller; | 142 StreamController controller; |
| 143 Timer timer; | 143 Timer timer; |
| 144 int counter = 0; | 144 int counter = 0; |
| 145 | 145 |
| 146 void tick(_) { | 146 void tick(_) { |
| 147 counter++; | 147 counter++; |
| 148 controller.add(counter); // Ask stream to send counter values as event. | 148 controller.add(counter); // Ask stream to send counter values as event. |
| 149 if (counter >= maxCount) { | 149 if (counter >= maxCount) { |
| 150 timer.cancel(); | 150 timer.cancel(); |
| 151 controller.close(); // Ask stream to shut down and tell listeners. | 151 controller.close(); // Ask stream to shut down and tell listeners. |
| 152 } | 152 } |
| 153 } | 153 } |
| 154 | 154 |
| 155 void startTimer() { | 155 void startTimer() { |
| 156 timer = new Timer.periodic(const Duration(milliseconds: 10), tick); | 156 timer = new Timer.periodic(const Duration(milliseconds: 10), tick); |
| 157 } | 157 } |
| 158 | 158 |
| 159 void stopTimer() { | 159 void stopTimer() { |
| 160 if (timer != null) { | 160 if (timer != null) { |
| 161 timer.cancel(); | 161 timer.cancel(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 } | 195 } |
| 196 | 196 |
| 197 controller = new StreamController( | 197 controller = new StreamController( |
| 198 onListen: startTimer, | 198 onListen: startTimer, |
| 199 onPause: stopTimer, | 199 onPause: stopTimer, |
| 200 onResume: startTimer, | 200 onResume: startTimer, |
| 201 onCancel: stopTimer); | 201 onCancel: stopTimer); |
| 202 | 202 |
| 203 return controller.stream; | 203 return controller.stream; |
| 204 } | 204 } |
| OLD | NEW |