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

Unified Diff: pkg/dev_compiler/tool/input_sdk/private/isolate_helper.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
« no previous file with comments | « no previous file | pkg/dev_compiler/tool/input_sdk/private/preambles/d8.js » ('j') | sdk/lib/async/timer.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/dev_compiler/tool/input_sdk/private/isolate_helper.dart
diff --git a/pkg/dev_compiler/tool/input_sdk/private/isolate_helper.dart b/pkg/dev_compiler/tool/input_sdk/private/isolate_helper.dart
index 039b14f08a1321e2f099f4d6bf3ec9eedf872fde..42b18249d37d4a8f4216f251e9b1c61d385760fc 100644
--- a/pkg/dev_compiler/tool/input_sdk/private/isolate_helper.dart
+++ b/pkg/dev_compiler/tool/input_sdk/private/isolate_helper.dart
@@ -1355,6 +1355,7 @@ class TimerImpl implements Timer {
final bool _once;
bool _inEventLoop = false;
int _handle;
+ int _tick = 0;
TimerImpl(int milliseconds, void callback()) : _once = true {
if (milliseconds == 0 && (!hasTimer() || _globalState.isWorker)) {
@@ -1380,6 +1381,7 @@ class TimerImpl implements Timer {
void internalCallback() {
_handle = null;
leaveJsAsync();
+ _tick = 1;
callback();
}
@@ -1397,7 +1399,16 @@ class TimerImpl implements Timer {
: _once = false {
if (hasTimer()) {
enterJsAsync();
+ int start = JS('int', 'Date.now()');
_handle = JS('int', '#.setInterval(#, #)', global, () {
+ int tick = this._tick + 1;
+ if (milliseconds > 0) {
+ int duration = JS('int', 'Date.now()') - start;
+ if (duration > (tick + 1) * milliseconds) {
+ tick = duration ~/ milliseconds;
+ }
+ }
+ this._tick = tick;
callback(this);
}, milliseconds);
} else {
@@ -1405,6 +1416,8 @@ class TimerImpl implements Timer {
}
}
+ int get tick => _tick;
+
void cancel() {
if (hasTimer()) {
if (_inEventLoop) {
« no previous file with comments | « no previous file | pkg/dev_compiler/tool/input_sdk/private/preambles/d8.js » ('j') | sdk/lib/async/timer.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698