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

Unified Diff: sdk/lib/async/timer.dart

Issue 23875032: Expose Zones. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebase Created 7 years, 3 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 | « sdk/lib/async/stream_impl.dart ('k') | sdk/lib/async/zone.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/async/timer.dart
diff --git a/sdk/lib/async/timer.dart b/sdk/lib/async/timer.dart
index 6c15c4baf70c6014f505c3d6a04f7b1fa61bcbf8..0fb0ceae26ff1972abd05307cf780eff752556d8 100644
--- a/sdk/lib/async/timer.dart
+++ b/sdk/lib/async/timer.dart
@@ -32,7 +32,7 @@ part of dart.async;
*
* Note: If Dart code using Timer is compiled to JavaScript, the finest
* granularity available in the browser is 4 milliseconds.
- *
+ *
* See [Stopwatch] for measuring elapsed time.
*/
abstract class Timer {
@@ -44,7 +44,13 @@ abstract class Timer {
*
*/
factory Timer(Duration duration, void callback()) {
- return _Zone.current.createTimer(duration, callback);
+ if (Zone.current == Zone.ROOT) {
+ // No need to bind the callback. We know that the root's timer will
+ // be invoked in the root zone.
+ return Zone.current.createTimer(duration, callback);
+ }
+ return Zone.current.createTimer(
+ duration, Zone.current.bindCallback(callback, runGuarded: true));
}
/**
@@ -55,7 +61,13 @@ abstract class Timer {
*/
factory Timer.periodic(Duration duration,
void callback(Timer timer)) {
- return _Zone.current.createPeriodicTimer(duration, callback);
+ if (Zone.current == Zone.ROOT) {
+ // No need to bind the callback. We know that the root's timer will
+ // be invoked in the root zone.
+ return Zone.current.createPeriodicTimer(duration, callback);
+ }
+ return Zone.current.createPeriodicTimer(
+ duration, Zone.current.bindUnaryCallback(callback, runGuarded: true));
}
/**
« no previous file with comments | « sdk/lib/async/stream_impl.dart ('k') | sdk/lib/async/zone.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698