Chromium Code Reviews| Index: sdk/lib/async/timer.dart |
| diff --git a/sdk/lib/async/timer.dart b/sdk/lib/async/timer.dart |
| index 6c15c4baf70c6014f505c3d6a04f7b1fa61bcbf8..1f1997655ed79bca2b157e99222bbf29c1388aa5 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.bindCallback1(callback, runGuarded: true)); |
|
Lasse Reichstein Nielsen
2013/09/23 14:24:12
bindCallbackUnary?
floitsch
2013/09/23 17:12:07
Done.
|
| } |
| /** |