Chromium Code Reviews| 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 typedef void _TimerCallback0(); | |
| 6 typedef void _TimerCallback1(Timer timer); | |
| 7 | |
| 8 patch class Timer { | 5 patch class Timer { |
| 9 /* patch */ factory Timer(var duration, Function callback) { | 6 /* patch */ factory Timer(Duration duration, void callback()) { |
| 10 // TODO(floitsch): remove these checks when we remove the deprecated | |
| 11 // millisecond argument and the 1-argument callback. Also remove | |
| 12 // the int-test below. | |
| 13 if (callback is! _TimerCallback0 && callback is! _TimerCallback1) { | |
| 14 throw new ArgumentError(callback); | |
| 15 } | |
| 16 int milliseconds = duration is int ? duration : duration.inMilliseconds; | |
| 17 if (milliseconds < 0) milliseconds = 0; | |
| 18 _TimerCallback1 oneArgumentCallback = | |
| 19 callback is _TimerCallback1 ? callback : (_) { callback(); }; | |
| 20 if (_TimerFactory._factory == null) { | 7 if (_TimerFactory._factory == null) { |
| 21 throw new UnsupportedError("Timer interface not supported."); | 8 throw new UnsupportedError("Timer interface not supported."); |
| 22 } | 9 } |
| 23 return _TimerFactory._factory(milliseconds, oneArgumentCallback, false); | 10 int milliseconds = duration.inMilliseconds; |
| 11 if (milliseconds < 0) milliseconds = 0; | |
|
Lasse Reichstein Nielsen
2013/02/28 11:14:48
Is that possible? I would have thought Duration di
floitsch
2013/02/28 13:24:05
Duration is a time-delta. We wouldn't even be able
| |
| 12 return _TimerFactory._factory(milliseconds, (_) { callback(); }, false); | |
| 24 } | 13 } |
| 25 | 14 |
| 26 /** | 15 /* patch */ factory Timer.repeating(Duration duration, |
| 27 * Creates a new repeating timer. The [callback] is invoked every | |
| 28 * [milliseconds] millisecond until cancelled. | |
| 29 */ | |
| 30 /* patch */ factory Timer.repeating(var duration, | |
| 31 void callback(Timer timer)) { | 16 void callback(Timer timer)) { |
| 32 if (_TimerFactory._factory == null) { | 17 if (_TimerFactory._factory == null) { |
| 33 throw new UnsupportedError("Timer interface not supported."); | 18 throw new UnsupportedError("Timer interface not supported."); |
| 34 } | 19 } |
| 35 // TODO(floitsch): remove this check when we remove the deprecated | 20 int milliseconds = duration.inMilliseconds; |
| 36 // millisecond argument. | |
| 37 int milliseconds = duration is int ? duration : duration.inMilliseconds; | |
| 38 if (milliseconds < 0) milliseconds = 0; | 21 if (milliseconds < 0) milliseconds = 0; |
| 39 return _TimerFactory._factory(milliseconds, callback, true); | 22 return _TimerFactory._factory(milliseconds, callback, true); |
| 40 } | 23 } |
| 41 } | 24 } |
| 42 | 25 |
| 43 typedef Timer _TimerFactoryClosure(int milliseconds, | 26 typedef Timer _TimerFactoryClosure(int milliseconds, |
| 44 void callback(Timer timer), | 27 void callback(Timer timer), |
| 45 bool repeating); | 28 bool repeating); |
| 46 | 29 |
| 47 class _TimerFactory { | 30 class _TimerFactory { |
| 48 static _TimerFactoryClosure _factory; | 31 static _TimerFactoryClosure _factory; |
| 49 } | 32 } |
| 50 | 33 |
| 51 // TODO(ahe): Warning: this is NOT called by Dartium. Instead, it sets | 34 // TODO(ahe): Warning: this is NOT called by Dartium. Instead, it sets |
| 52 // [_TimerFactory._factory] directly. | 35 // [_TimerFactory._factory] directly. |
| 53 void _setTimerFactoryClosure(_TimerFactoryClosure closure) { | 36 void _setTimerFactoryClosure(_TimerFactoryClosure closure) { |
| 54 _TimerFactory._factory = closure; | 37 _TimerFactory._factory = closure; |
| 55 } | 38 } |
| OLD | NEW |