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

Unified Diff: runtime/lib/timer_impl.dart

Issue 3003853002: Add ticks counter to Timer. (Closed)
Patch Set: Test that tick increments by more than one Created 3 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: runtime/lib/timer_impl.dart
diff --git a/runtime/lib/timer_impl.dart b/runtime/lib/timer_impl.dart
index 8c0a670abdfdaedafdb94b18d33dc589c7e4e2fa..fb0dfa897e49dae346c0cb158cb62af63bf1288a 100644
--- a/runtime/lib/timer_impl.dart
+++ b/runtime/lib/timer_impl.dart
@@ -146,6 +146,8 @@ class _Timer implements Timer {
var _indexOrNext; // Index if part of the TimerHeap, link otherwise.
int _id; // Incrementing id to enable sorting of timers with same expiry.
+ int _tick = 0; // Backing for [tick],
+
// Get the next available id. We accept collisions and reordering when the
// _idCount overflows and the timers expire at the same millisecond.
static int _nextId() {
@@ -197,6 +199,8 @@ class _Timer implements Timer {
bool get isActive => _callback != null;
+ int get tick => _tick;
+
// Cancels a set timer. The timer is removed from the timer heap if it is a
// non-zero timer. Zero timers are kept in the list as they need to consume
// the corresponding pending message.
@@ -363,7 +367,18 @@ class _Timer implements Timer {
if (!timer._repeating) {
// Mark timer as inactive.
timer._callback = null;
+ } else if (timer._milliSeconds > 0) {
+ var ms = timer._milliSeconds;
+ int overdue =
+ VMLibraryHooks.timerMillisecondClock() - timer._wakeupTime;
+ if (overdue > ms) {
+ int missedTicks = overdue ~/ ms;
+ timer._wakeupTime += missedTicks * ms;
+ timer._tick += missedTicks;
+ }
}
+ timer._tick += 1;
+
callback(timer);
// Re-insert repeating timer if not canceled.
if (timer._repeating && (timer._callback != null)) {

Powered by Google App Engine
This is Rietveld 408576698