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

Unified Diff: sdk/lib/_internal/lib/isolate_helper.dart

Issue 18325006: Add isActive field on Timer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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 | sdk/lib/async/timer.dart » ('j') | sdk/lib/async/timer.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/lib/isolate_helper.dart
diff --git a/sdk/lib/_internal/lib/isolate_helper.dart b/sdk/lib/_internal/lib/isolate_helper.dart
index 47df338e5fa0c3b3255a89dc638496510d7d7beb..d13095e41af6809b39b1aceb39189d36624ccf02 100644
--- a/sdk/lib/_internal/lib/isolate_helper.dart
+++ b/sdk/lib/_internal/lib/isolate_helper.dart
@@ -1360,6 +1360,16 @@ class TimerImpl implements Timer {
TimerImpl(int milliseconds, void callback())
: _once = true {
if (milliseconds == 0 && (!hasTimer() || _globalState.isWorker)) {
+
+ void internalCallback() {
+ _handle = null;
+ callback();
+ }
+
+ // Setting _handle to something different from null indicates that the
+ // callback has not been run. Hence, the choice of 1 is arbitrary.
+ _handle = 1;
+
// This makes a dependency between the async library and the
// event loop of the isolate library. The compiler makes sure
// that the event loop is compiled if [Timer] is used.
@@ -1367,15 +1377,17 @@ class TimerImpl implements Timer {
// loop instead of setTimeout, to make sure the futures get executed in
// order.
_globalState.topEventLoop.enqueue(
- _globalState.currentContext, callback, 'timer');
+ _globalState.currentContext, internalCallback, 'timer');
_inEventLoop = true;
} else if (hasTimer()) {
- _globalState.topEventLoop.activeTimerCount++;
+
void internalCallback() {
- callback();
_handle = null;
_globalState.topEventLoop.activeTimerCount--;
+ callback();
}
+
+ _globalState.topEventLoop.activeTimerCount++;
_handle = JS('int', '#.setTimeout(#, #)',
globalThis,
convertDartClosureToJS(internalCallback, 0),
@@ -1416,6 +1428,8 @@ class TimerImpl implements Timer {
throw new UnsupportedError("Canceling a timer.");
}
}
+
+ bool get isActive => (_handle != null);
}
bool hasTimer() => JS('', '#.setTimeout', globalThis) != null;
« no previous file with comments | « no previous file | sdk/lib/async/timer.dart » ('j') | sdk/lib/async/timer.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698