Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: pkg/scheduled_test/lib/src/mock_clock.dart

Issue 12452008: Stop working around issue 8512. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | utils/pub/error_group.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /// A library that wraps [Timer] in a way that can be mocked out in test code. 5 /// A library that wraps [Timer] in a way that can be mocked out in test code.
6 /// Application code only needs to use [newTimer] to get an instance of [Timer]. 6 /// Application code only needs to use [newTimer] to get an instance of [Timer].
7 /// Then test code can call [mock] to mock out all new [Timer] instances so that 7 /// Then test code can call [mock] to mock out all new [Timer] instances so that
8 /// they're controllable by a returned [Clock] object. 8 /// they're controllable by a returned [Clock] object.
9 library mock_clock; 9 library mock_clock;
10 10
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 class _MockTimer implements Timer { 79 class _MockTimer implements Timer {
80 /// The time at which the timer should fire. 80 /// The time at which the timer should fire.
81 final int _time; 81 final int _time;
82 82
83 /// The callback to run when the timer fires. 83 /// The callback to run when the timer fires.
84 final TimerCallback _callback; 84 final TimerCallback _callback;
85 85
86 /// The subscription to the [Clock.onTick] stream. 86 /// The subscription to the [Clock.onTick] stream.
87 StreamSubscription _subscription; 87 StreamSubscription _subscription;
88 88
89 // TODO(nweiz): Remove this when issue 8512 is fixed.
90 var _cancelled = false;
91
92 _MockTimer(Duration duration, this._callback) 89 _MockTimer(Duration duration, this._callback)
93 : _time = _clock.time + duration.inMilliseconds { 90 : _time = _clock.time + duration.inMilliseconds {
94 _subscription = _clock.onTick.listen((time) { 91 _subscription = _clock.onTick.listen((time) {
95 if (_cancelled || time < _time) return; 92 if (time < _time) return;
96 _subscription.cancel(); 93 _subscription.cancel();
97 _callback(); 94 _callback();
98 }); 95 });
99 } 96 }
100 97
101 void cancel() { 98 void cancel() => _subscription.cancel();
102 _cancelled = true;
103 _subscription.cancel();
104 }
105 } 99 }
OLDNEW
« no previous file with comments | « no previous file | utils/pub/error_group.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698