Index: pkg/scheduled_test/lib/src/mock_clock.dart |
diff --git a/pkg/scheduled_test/lib/src/mock_clock.dart b/pkg/scheduled_test/lib/src/mock_clock.dart |
index c80a9552661329cf8e4402afdb4bddf75652d473..46a37afcf2e246453071150d5b44fac314843f67 100644 |
--- a/pkg/scheduled_test/lib/src/mock_clock.dart |
+++ b/pkg/scheduled_test/lib/src/mock_clock.dart |
@@ -44,27 +44,14 @@ class Clock { |
int get time => _time; |
int _time = 0; |
- /// Collection of controllers of all subscribed listeners. |
- /// |
- /// [StreamController] is not overriding [Object.operator==], so this is |
- /// effectively an identity map. |
- Set<StreamController> _subscriptions = new Set<StreamController>(); |
+ /// Controller providing streams for listening. |
+ StreamController<int> _multiplexController = |
+ new StreamController<int>.multiplex(); |
Clock._(); |
/// The stream of millisecond ticks of the clock. |
- Stream<int> get onTick { |
- StreamController<int> controller; |
- controller = new StreamController<int>( |
- onListen: () { |
- _subscriptions.add(controller); |
- }, |
- onCancel: () { |
- _subscriptions.remove(controller); |
- }); |
- return controller.stream; |
- } |
- |
+ Stream<int> get onTick => _multiplexController.stream; |
/// Advances the clock forward by [milliseconds]. This works like synchronous |
/// code that takes [milliseconds] to execute; any [Timer]s that are scheduled |
@@ -74,12 +61,7 @@ class Clock { |
for (var i = 0; i < milliseconds; i++) { |
var tickTime = ++_time; |
runAsync(() { |
- List<StreamController> controllers = _subscriptions.toList(); |
- for (StreamController controller in controllers) { |
- if (_subscriptions.contains(controller)) { |
- controller.add(tickTime); |
- } |
- } |
+ _multiplexController.add(tickTime); |
}); |
} |
} |
@@ -90,7 +72,7 @@ class Clock { |
/// code runs before the next tick. |
void run() { |
pumpEventQueue().then((_) { |
- if (_subscriptions.isEmpty) return; |
+ if (!_multiplexController.hasListener) return; |
tick(); |
return run(); |
}); |