| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 Stream timedCounter(int maxCount) { | 93 Stream timedCounter(int maxCount) { |
| 94 StreamController controller; | 94 StreamController controller; |
| 95 Timer timer; | 95 Timer timer; |
| 96 int counter = 0; | 96 int counter = 0; |
| 97 | 97 |
| 98 void tick(_) { | 98 void tick(_) { |
| 99 counter++; | 99 counter++; |
| 100 controller.add(counter); // Ask stream to send counter values as event. | 100 controller.add(counter); // Ask stream to send counter values as event. |
| 101 if (counter >= maxCount) { | 101 if (counter >= maxCount) { |
| 102 timer.cancel(); | 102 timer.cancel(); |
| 103 controller.close(); // Ask stream to shut down and tell listeners. | 103 controller.close(); // Ask stream to shut down and tell listeners. |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 | 106 |
| 107 void startTimer() { | 107 void startTimer() { |
| 108 timer = new Timer.periodic(const Duration(milliseconds: 10), tick); | 108 timer = new Timer.periodic(const Duration(milliseconds: 10), tick); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void stopTimer() { | 111 void stopTimer() { |
| 112 if (timer != null) { | 112 if (timer != null) { |
| 113 timer.cancel(); | 113 timer.cancel(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 147 } |
| 148 | 148 |
| 149 controller = new StreamController( | 149 controller = new StreamController( |
| 150 onListen: startTimer, | 150 onListen: startTimer, |
| 151 onPause: stopTimer, | 151 onPause: stopTimer, |
| 152 onResume: startTimer, | 152 onResume: startTimer, |
| 153 onCancel: stopTimer); | 153 onCancel: stopTimer); |
| 154 | 154 |
| 155 return controller.stream; | 155 return controller.stream; |
| 156 } | 156 } |
| OLD | NEW |