| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 patch class Timer { | 5 patch Timer _createTimer(Duration duration, void callback()) { |
| 6 /* patch */ factory Timer(Duration duration, void callback()) { | 6 if (_TimerFactory._factory == null) { |
| 7 if (_TimerFactory._factory == null) { | 7 throw new UnsupportedError("Timer interface not supported."); |
| 8 throw new UnsupportedError("Timer interface not supported."); | |
| 9 } | |
| 10 int milliseconds = duration.inMilliseconds; | |
| 11 if (milliseconds < 0) milliseconds = 0; | |
| 12 return _TimerFactory._factory(milliseconds, (_) { callback(); }, false); | |
| 13 } | 8 } |
| 9 int milliseconds = duration.inMilliseconds; |
| 10 if (milliseconds < 0) milliseconds = 0; |
| 11 return _TimerFactory._factory(milliseconds, (_) { callback(); }, false); |
| 12 } |
| 14 | 13 |
| 15 /* patch */ factory Timer.periodic(Duration duration, | 14 patch Timer _createPeriodicTimer(Duration duration, |
| 16 void callback(Timer timer)) { | 15 void callback(Timer timer)) { |
| 17 if (_TimerFactory._factory == null) { | 16 if (_TimerFactory._factory == null) { |
| 18 throw new UnsupportedError("Timer interface not supported."); | 17 throw new UnsupportedError("Timer interface not supported."); |
| 19 } | |
| 20 int milliseconds = duration.inMilliseconds; | |
| 21 if (milliseconds < 0) milliseconds = 0; | |
| 22 return _TimerFactory._factory(milliseconds, callback, true); | |
| 23 } | 18 } |
| 19 int milliseconds = duration.inMilliseconds; |
| 20 if (milliseconds < 0) milliseconds = 0; |
| 21 return _TimerFactory._factory(milliseconds, callback, true); |
| 24 } | 22 } |
| 25 | 23 |
| 24 |
| 26 typedef Timer _TimerFactoryClosure(int milliseconds, | 25 typedef Timer _TimerFactoryClosure(int milliseconds, |
| 27 void callback(Timer timer), | 26 void callback(Timer timer), |
| 28 bool repeating); | 27 bool repeating); |
| 29 | 28 |
| 30 class _TimerFactory { | 29 class _TimerFactory { |
| 31 static _TimerFactoryClosure _factory; | 30 static _TimerFactoryClosure _factory; |
| 32 } | 31 } |
| 33 | 32 |
| 34 // TODO(ahe): Warning: this is NOT called by Dartium. Instead, it sets | 33 // TODO(ahe): Warning: this is NOT called by Dartium. Instead, it sets |
| 35 // [_TimerFactory._factory] directly. | 34 // [_TimerFactory._factory] directly. |
| 36 void _setTimerFactoryClosure(_TimerFactoryClosure closure) { | 35 void _setTimerFactoryClosure(_TimerFactoryClosure closure) { |
| 37 _TimerFactory._factory = closure; | 36 _TimerFactory._factory = closure; |
| 38 } | 37 } |
| OLD | NEW |